全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
5094 16
2015-05-24
如题:
我有些销售的数据第一列是产品编号400-200-21,400-200-22等,第二列是销售量2000,3000等.现在想把编号相同的产品销售量加起来构成该类产品的销量

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

扫码加我 拉你入群

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

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

全部回复
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;
二维码

扫码加我 拉你入群

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

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

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群