2016-02-26 307 views
0

我正在计算年平均值和最高和最低温度的标准偏差,。我的代码如下:SAS PROC SQL计算平均值时出错

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; 

我的代码最终吐在这样的东西上;

enter image description here

它重复YEAR2和年份列(我只想要一个用正确的一年,即1916.1917),并保持了一年重新计算。我怎么才能让我看看我的数据中50年的单一计算? (即排除重新计算)

+0

问题是这样的代码:'年(日期)为一年,(日期)作为year'。给两列命名是没有意义的。 –

+0

我已经纠正了,但现在它提出了另一个问题。更新一个问题的时刻。 –

+1

删除您的第一个proc sql,并在您的work.ROCH表中指向第二个。 – Reeza

回答

1

由于这是您第4次提出同样的问题,这里有一个答案,但我没有看到其他几个人出了什么问题。 使用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;