SAS PROC SQL 计算平均值时出错

SAS PROC SQL Error while computing averages

我正在尝试计算最高和最低温度的年平均值和标准差,。我的代码如下:

 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;

我的代码最终会吐出类似这样的东西;

它重复 year2 和年份列(我只想要一个具有正确年份的年份,即 1916.1917)并不断重新计算单个年份。我如何让它显示我数据中 50 年的单一计算? (即排除重新计算)

由于这是您第 4 次问同样的问题,所以这里有一个答案,但我看不出其他几个问题有什么问题。 使用 proc 手段的两种方式。您可以使用输出或 ODS 输出,我已经对两者进行了编码,但它不是 required.Your 最终结果是 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;

使用过程 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;