SAS中文论坛
标题:
该如何统计这些数据呢?
[打印本页]
作者:
shiyiming
时间:
2004-10-24 23:57
标题:
该如何统计这些数据呢?
我有气候站点的一些气温原始数据,数据格式是这样的:
sta_id year m d cl1 cl2 cl3
50353 1991 05 01 72 071 063
50353 1991 05 02 080 067 040
50353 1991 05 03 103 111 067
50353 1991 05 04 087 089 065
50353 1991 05 05 093 080 125
50353 1991 05 06 059 051 043
……
52818 1992 01 01 -061 -044 -033
52818 1992 01 02 -065 -047 -035
52818 1992 01 03 -067 -049 -036
52818 1992 01 04 -060 -047 -037
……
其中sta_id有100个不同站点,year从1991―2000,后面的月和日期两个变量分别从1-12月,1日至31日或30日。cl1-cl3是三个不同海拔的每日温度(单位为0.1度)。
我想统计出一张10年各站点按月平均温度的表,包括变量为sta_id(100个站点的id),month(月份,从1-12),以及cl1-cl3。也就是说,要生成100个不同sta_id点从1-12月份共十年的月平均cl1-cl3数据。
我捣鼓了很久,又是用if语句又是用do-end,就是编不出这个程序来,自己的思路也不清楚,所以烦高手指点迷津!感激涕零!
作者:
shiyiming
时间:
2004-10-25 05:25
标题:
细节没考虑,大概是这个意思
data temp;
input sta_id year m d cl1 cl2 cl3 ;
datalines;
50353 1991 05 01 72 071 063
50353 1991 05 02 080 067 040
50353 1991 05 03 103 111 067
50353 1991 05 04 087 089 065
50353 1991 05 05 093 080 125
50353 1991 05 06 059 051 043
52818 1992 01 01 -061 -044 -033
52818 1992 01 02 -065 -047 -035
52818 1992 01 03 -067 -049 -036
52818 1992 01 04 -060 -047 -037
;
run;;
proc print data=temp;
run;
方法一:
proc means data=temp;
var cl1 cl2 cl3;
by sta_id year m;
run;
方法二:
proc sql;
select * ,mean(cl1) as cl1mean, mean(cl2) as cl2mean ,mean(cl3) as cl3mean
from temp
group by sta_id ,year, m;
quit;
方法三:
proc sort data=temp;
by sta_id year m;
run;
data xyz;
set temp;
by sta_id year m;
if first.sta_id=1 or first.m=1 then
do;
cl1tot=0;
cl2tot=0;
cl3tot=0;
cl1mean=0;
cl2mean=0;
cl3mean=0;
n=0;
end;
cl1tot+cl1;
cl2tot+cl2;
cl3tot+cl3;
n+1;
if last.sta_id=1 or last.m=1 then
do;
cl1mean=cl1tot/n;
cl2mean=cl2tot/n;
cl3mean=cl3tot/n;
output;
end;
run;
作者:
shiyiming
时间:
2004-10-25 13:41
标题:
re
非常感谢smartie!
Let me try!
作者:
shiyiming
时间:
2004-10-25 14:05
标题:
re
第三个程序很好用,第二个好像有些问题。总之太谢谢了!
作者:
shiyiming
时间:
2004-10-25 21:10
标题:
有什么问题
能否说一下,我好继续改进,另外,为什么不用第一个,应该是最好的
欢迎光临 SAS中文论坛 (https://mysas.net/forum/)
Powered by Discuz! X3.2