由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Statistics版 - Please help with a SAS macro
相关主题
请问如果用SAS 解决这个问题请教一个简单SAS问题
请教flag问题问一个SAS 的问题
问个PROC SQL中INNER JOIN的问题怎么用SAS transpose这两dataset呀?
怎样储存我想要的proc means 的结果?SAS question: count non-missing value for different variables
请问R Code和 Matlab Code 思路是否近似?[合集] how to calculate column sum not row sum in SAS? thanks a lo
请教一下SAS编程的一个问题SAS菜鸟请教如果使SAS的output的结果放到一个文件内?
SAS code help请教SAS LABEL问题。
问SAS code怎么写急问一个call symput问题(SAS)
相关话题的讨论汇总
话题: var2话题: month话题: var1话题: sas话题: macro
进入Statistics版参与讨论
1 (共1页)
j*****1
发帖数: 75
1
Sorry can't type Chinese.
Can anyone please help me with a SAS macro? I have a dataset includes
Month and Var1 (please see the dataset below) and I need to create a field
Var2, which is the mean of previous months' Var1.
For example, for Month 201401, var2= mean of 2.
for Month 201402 var2= mean of 2,4
for month 201404 var2 = mean of 2,4,5,8
etc......
Month Var1 Var2
201401 2 2.00
201402 4 3.00
201403 5 3.67
201404 8 4.75
201405 10 5.80
201406 12 6.83
201407 21 8.86
Thank you!
s*******e
发帖数: 1385
2
我没有SAS,你可以试试这个程序。
data temp;
set yourdata;
retain total 0;
var2=(total+var1)/_N_;
run;

field

【在 j*****1 的大作中提到】
: Sorry can't type Chinese.
: Can anyone please help me with a SAS macro? I have a dataset includes
: Month and Var1 (please see the dataset below) and I need to create a field
: Var2, which is the mean of previous months' Var1.
: For example, for Month 201401, var2= mean of 2.
: for Month 201402 var2= mean of 2,4
: for month 201404 var2 = mean of 2,4,5,8
: etc......
: Month Var1 Var2
: 201401 2 2.00

s*********e
发帖数: 1051
3
data one (drop = var2);
input Month Var1 Var2;
datalines;
201401 2 2.00
201402 4 3.00
201403 5 3.67
201404 8 4.75
201405 10 5.80
201406 12 6.83
201407 21 8.86
;
run;
proc sql;
create table two as
select b_month, mean(a_var1) as var2
from
(select
a.month as a_month,
b.month as b_month,
a.var1 as a_var1
from one as a, one as b where a.month <= b.month)
group by b_month;
quit;
proc print data =two;
run;
j*****1
发帖数: 75
4
谢谢大家的帮助!
m***c
发帖数: 118
5
proc sort data=one; by month var; run;
data two; set one; by month var;
var2+var1;
var2/_n_;
run;
飞越
1 (共1页)
进入Statistics版参与讨论
相关主题
急问一个call symput问题(SAS)请问R Code和 Matlab Code 思路是否近似?
%do questions请教一下SAS编程的一个问题
SAS problem ask for help!SAS code help
求助:一个SAS小程序问SAS code怎么写
请问如果用SAS 解决这个问题请教一个简单SAS问题
请教flag问题问一个SAS 的问题
问个PROC SQL中INNER JOIN的问题怎么用SAS transpose这两dataset呀?
怎样储存我想要的proc means 的结果?SAS question: count non-missing value for different variables
相关话题的讨论汇总
话题: var2话题: month话题: var1话题: sas话题: macro