powermax
原数据集a是每周价格数据,有2个变量 t 和price
t price
1997-1-3
1997-1-10
1997-1-17
1997-1-24
1997-1-31
1997-2-7
1997-2-14
1997-2-21
1997-2-28
1997-3-7
……
……
现在想做2种处理 :一是计算每月的平均价格,生成新的数据集b
二是取每月第一周的观察值生成新的数据集c
请问用sas如何实现呢 谢谢!
abel
proc sql做这个工作足够了
当然,也可以使用传统的sas proc
powermax
具体怎么实现恩 用sas proc
zhanjian
data a;
input month income ;
cards;
1 23
1 34
1 45
2 56
2 20
2 43
3 45
3 29
3 46
;
run;
data b;
set a;
by month;
if first.month=1 then time=1 ;
else time+1;
run;
data c ;
set b;
if time=1;
drop time ;
run;
供参考(第二问)
zhanjian
data a;
input month income ;
cards;
1 23
1 34
1 45
2 56
2 20
2 43
3 45
3 29
3 46
;
run;
proc sql;
select month, avg(income) as mincome from a
group by month;
ods output data=e;
quit;
参考 第一题
leeyoung613
**1.Calculate average price of every month;
data a;
input t yymmdd10. price;
format t yymmdd10.;
cards;
1997-1-3 789
1997-1-10 876
1997-1-17 565
1997-1-24 876
1997-1-31 864
1997-2-7 567
1997-2-14 354
1997-2-21 976
1997-2-28 876
1997-3-7 865
1997-3-14 655
1997-3-21 457
1997-3-28 976
;
run;
data b;
set a;
year=year(t);
month=month(t);
day=day(t);
drop t;
run;
proc sql;
create table Answer1 as
select year, month, mean(price) as avg_price from b
group by year, month;
quit;
**2.Select the observation of the first week of every month;
data Answer2;
set b;
if day>7 then delete;
run;
leeyoung613
Answer1 和Answer2就是所求的数据集