楼主: 维兹
4706 16

sas可以通过查找编号相同的列将值相加么 [推广有奖]

  • 7关注
  • 0粉丝

硕士生

46%

还不是VIP/贵宾

-

威望
0
论坛币
482 个
通用积分
0.1271
学术水平
1 点
热心指数
2 点
信用等级
0 点
经验
2252 点
帖子
121
精华
0
在线时间
114 小时
注册时间
2014-7-6
最后登录
2018-12-12

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
如题:
我有些销售的数据第一列是产品编号400-200-21,400-200-22等,第二列是销售量2000,3000等.现在想把编号相同的产品销售量加起来构成该类产品的销量

这个过程可以用sas实现么?谢谢
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:销售量 产品 销售量

回帖推荐

舍身卫道 发表于13楼  查看完整内容

我没有你的源数据集没法测试,你用下面修改之后程序在测试一下 data test_1; do i=1 to 24; if i

舍身卫道 发表于8楼  查看完整内容

data test; length cp_bm $16. xsl 8. pp 8.; input cp_bm xsl pp; cards; 400-200-21 2000 10 400-200-21 5000 3 400-200-21 1000 90 400-200-22 500 32 400-200-22 1500 24 400-200-20 5000 87 400-200-20 7000 13 ; run; proc sort data=test out=test_s;by cp_bm;run; data rslt_1; set test_s; by cp_bm; if first.cp_bm then do; flag1=0; flag2=0; end; flag1+xsl; flag2+pp; if last.cp_bm ...

舍身卫道 发表于4楼  查看完整内容

data test; length cp_bm $16. xsl 8.; input cp_bm xsl; cards; 400-200-21 2000 400-200-21 5000 400-200-21 1000 400-200-22 500 400-200-22 1500 400-200-20 5000 400-200-20 7000 ; run; proc sort data=test out=test_s;by cp_bm;run; data rslt_1; set test_s; by cp_bm; if first.cp_bm then flag=xsl; flag+xsl; if last.cp_bm then output; drop xsl; run; 这样可以吗?
沙发
舍身卫道 发表于 2015-5-25 00:06:47 |只看作者 |坛友微信交流群
/*cp_bm 为产品编码 xsl 为销售量*/
/*样例数据*/
data  test;
length cp_bm $16. xsl 8.;
input cp_bm $ xsl;
cards;
400-200-21 2000
400-200-21 5000
400-200-21 1000
400-200-22 500
400-200-22 1500
400-200-20 5000
400-200-20 7000
;
run;
proc summary data=test nway missing;
class cp_bm;
var xsl;
output out=test_sum(drop=_type_) sum=;
run;

使用道具

藤椅
维兹 发表于 2015-5-25 14:50:17 |只看作者 |坛友微信交流群
舍身卫道 发表于 2015-5-25 00:06
/*cp_bm 为产品编码 xsl 为销售量*/
/*样例数据*/
data  test;
如果同时还有别的变量 比如产品生产商ID之类的  我想要把销量累计以后 其他变量照写可以实现么

使用道具

板凳
舍身卫道 发表于 2015-5-25 15:03:43 |只看作者 |坛友微信交流群
data  test;
length cp_bm $16. xsl 8.;
input cp_bm xsl;
cards;
400-200-21 2000
400-200-21 5000
400-200-21 1000
400-200-22 500
400-200-22 1500
400-200-20 5000
400-200-20 7000
;
run;

proc sort data=test out=test_s;by cp_bm;run;

data rslt_1;
set test_s;
by cp_bm;
if first.cp_bm then flag=xsl;
flag+xsl;
if last.cp_bm then output;
drop xsl;
run;
这样可以吗?

使用道具

报纸
维兹 发表于 2015-5-25 15:46:57 |只看作者 |坛友微信交流群
舍身卫道 发表于 2015-5-25 15:03
data  test;
length cp_bm $16. xsl 8.;
input cp_bm xsl;
可以的 还有问题 就是我需要累加的不止一列 除了销售量意外 还有销售额也需要累加 我刚才尝试写成
proc sort data=test out=test_s;by cp_bm;run;

data rslt_1;
set test_s;
by cp_bm;
if first.cp_bm then flag1=var5 flag2=var6;
flag+var5 flag+var6;
if last.cp_bm then output;
drop var5 var6;
run;


然后失败了 想请教一下能不能改动一下 增加累加的变量个数

非常感谢你~

使用道具

地板
舍身卫道 发表于 2015-5-25 15:52:58 |只看作者 |坛友微信交流群


data  test;
length cp_bm $16. xsl 8. pp 8.;
input cp_bm xsl pp;
cards;
400-200-21 2000 10
400-200-21 5000 3
400-200-21 1000 90
400-200-22 500 32
400-200-22 1500 24
400-200-20 5000 87
400-200-20 7000 13
;
run;

proc sort data=test out=test_s;by cp_bm;run;

data rslt_1;
set test_s;
by cp_bm;
if first.cp_bm then
do;
flag1=xsl;
flag2=pp;
end;
flag1+xsl;
flag2+pp;
if last.cp_bm then output;
drop xsl pp;
run;

使用道具

7
维兹 发表于 2015-5-25 16:19:35 |只看作者 |坛友微信交流群
舍身卫道 发表于 2015-5-25 15:52
data  test;
length cp_bm $16. xsl 8. pp 8.;
input cp_bm xsl pp;
我刚才算了一下 发现一个问题 就是这样做出来好像把检测到的第一个值累加了两次
但是用你给的第一种方法(class那个方法)计算出来是正确的结果

再麻烦你看一下 谢谢



使用道具

8
舍身卫道 发表于 2015-5-25 16:24:03 |只看作者 |坛友微信交流群
data  test;
length cp_bm $16. xsl 8. pp 8.;
input cp_bm xsl pp;
cards;
400-200-21 2000 10
400-200-21 5000 3
400-200-21 1000 90
400-200-22 500 32
400-200-22 1500 24
400-200-20 5000 87
400-200-20 7000 13
;
run;

proc sort data=test out=test_s;by cp_bm;run;

data rslt_1;
set test_s;
by cp_bm;
if first.cp_bm then
do;
flag1=0;
flag2=0;
end;
flag1+xsl;
flag2+pp;
if last.cp_bm then output;
drop xsl pp;
run;
刚才测试了一下,可以了

使用道具

9
维兹 发表于 2015-5-25 16:32:33 |只看作者 |坛友微信交流群
舍身卫道 发表于 2015-5-25 16:24
data  test;
length cp_bm $16. xsl 8. pp 8.;
input cp_bm xsl pp;
OK啦~~

谢谢

使用道具

10
维兹 发表于 2015-5-25 18:44:05 |只看作者 |坛友微信交流群
舍身卫道 发表于 2015-5-25 16:24
data  test;
length cp_bm $16. xsl 8. pp 8.;
input cp_bm xsl pp;
不好意思再打扰一下

我想把这个过程写成循环 在所有表格中运行,然后写成了下面这个样子 结果失败了。我并不明白大部分代码的实际含义,我就按照之前的循环格式套用的,所以不知道哪里有问题,请你帮我看一下可以么?谢谢

data test_1;
do i=1 to 24;
if i<10 then n=compress("0"||i);
else n=compress(i);
output;
end;
keep n;
run;


data _null_;
set test_1 end=last;
call symput(compress("F_name"||(_n_)),compress(n));
if last then call symput("sum",compress(_N_));
run;

%macro freq();
%do i=1 %to 99
proc sort data=new_&&F_name&i. out=test_&&F_name&i.;
by enb_id;run;

data data_&&F_name&i.;
set test_&&F_name&i.;
by enb_id;
if first.enb_id then
do;
flag1=0;
flag2=0;
end;
flag1+var6;
flag2+var7;
if last.enb_id then output;
drop var6 var7;
run;
%end;
%mend;
%freq()

使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-4-28 16:41