sas Proc 扩展过程
sas Proc expand procedure
我正在尝试按国家/地区的产品计算以下数据的 3 个月移动平均值(我这里只有两个国家/地区变量)。有办法吗?
这是销售额table我有:
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;
在我的评论之后我测试了一下,我想连接产品和国家会给出你正在寻找的结果(我希望我仍然没有理解错误):
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;
结果:
我正在尝试按国家/地区的产品计算以下数据的 3 个月移动平均值(我这里只有两个国家/地区变量)。有办法吗?
这是销售额table我有:
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;
在我的评论之后我测试了一下,我想连接产品和国家会给出你正在寻找的结果(我希望我仍然没有理解错误):
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;
结果: