sas Proc扩展程序

时间:2015-10-06 19:33:06

标签: sas expand proc

我正在尝试按国家/地区计算以下数据的3个月移动平均值(此处我只有两个国家/地区变量)。有办法吗?

这是我的销售表:

Date    Product  Country   Sales
201101  Sofa     US        100
201102  Sofa     US        200
201103  Sofa     US        250
201104  Sofa     US        300
201101  Sofa     CA        250
201102  Sofa     CA        300
201103  Sofa     CA        250
201104  Sofa     CA        300
201101  Chair    US        300
201102  Chair    US        300
201103  Chair    US        300
201104  Chair    US        300
201101  Chair    CA        300
201102  Chair    CA        300
201103  Chair    CA        300
201104  Chair    CA        300

我尝试了类似下面的内容,但移动平均线只按国家/地区计算。有没有办法按国家/地区按产品计算?任何想法将不胜感激。感谢:)

PROC SORT DATA=Sales;
BY Country Product Date;
RUN;

PROC EXPAND DATA=Sales out =ma;
By Country Product;
CONVERT Value=Value_ma/transformin=(setmiss 0) transformout=(movave 3);
run;

1 个答案:

答案 0 :(得分:0)

在我的评论之后,我测试了一下,我想联合产品和国家给出你正在寻找的结果(我希望我仍然没有理解错误):

data have;
input Date $ Product $ Country $ Sales ; 
datalines; 
201101  Sofa     US        100 
201102  Sofa     US        200 
201103  Sofa     US        250 
201104  Sofa     US        300 
201101  Sofa     CA        250 
201102  Sofa     CA        300 
201103  Sofa     CA        250 
201104  Sofa     CA        300 
201101  Chair    US        300 
201102  Chair    US        300 
201103  Chair    US        300 
201104  Chair    US        300 
201101  Chair    CA        300 
201102  Chair    CA        300 
201103  Chair    CA        300 
201104  Chair    CA        300 
; 
run;

data have ;
set have; 
copr=catx("_",Product,country); 
run; 
PROC SORT DATA=have; 
BY copr Date; 
RUN;

PROC EXPAND DATA=have out =ma  ; 
 By copr; 
CONVERT sales=average /    transformin=(setmiss 0) transformout=(movave 3); 
run;

proc print data=ma; 
 var date product country average; 
where time > 1; 
run;

结果:

enter image description here