我试图计算年平均值和最高和最低温度的标准偏差。我的代码如下:
PROC SQL;
create table new2 as
select date,SUM(max_temp) as max_temp,SUM(min_temp) as min_temp,
SUM(precip) as precip
from WORK.ROCH_DATA
group by date;
create table average2 as
select year(date) as year,(date) as year2,avg(max_temp) as maxavg,
avg(min_temp) as minavg, avg(precip) as avgprecip, std(max_temp) as
stdmaxtemp,
std(min_temp) as stdmintemp,std(precip) as stdprecip
from new2
group by year;
QUIT;
我的代码最终吐出了类似的东西;
它重复了第二年和第二年专栏(我只想要一个适当的年份,即1916.1917),并不断重新计算一年。我如何让它向我展示我数据中50年的单一计算? (即排除重新计算)
答案 0 :(得分:1)
因为这是你第四次问同样的问题,这是一个答案,虽然我没有看到其他几个问题出了什么问题。 两种使用proc的方法。您可以使用输出或ODS OUTPUT,我已对两者进行了编码但不是必需的。您的最终结果是3个数据集应该具有您想要的,可能采用不同的格式。
proc means data=roch_data noprint stackods;
class date;
format date year4.;
var max_temp min_temp precip;
output out=summary_proc_mean1 mean= std= /autoname;
ods output summary=summary_proc_mean2;
run;
使用Proc SQL
PROC SQL;
create table average2 as
select year(date) as year,
avg(max_temp) as maxavg,
avg(min_temp) as minavg,
avg(precip) as avgprecip,
std(max_temp) as stdmaxtemp,
std(min_temp) as stdmintemp,
std(precip) as stdprecip
from roch_data
group by year;
QUIT;