I have an SAS program In which I am trying to print only one observation at the end of the file, That observation needs to contain the arithmetic means of 5 variables. When I run the program I have. I get an error that says
This is my program
Filename MyFile '/home/mrohde0/MyFolder/HWData/Funddrive.dat';
libname MyLib '/home/mrohde0/MyFolder/HWData/';
data MyLib.Fund_Avg(drop= Qtr1 Qtr2 Qtr3 Qtr4 AGEGP Year_Don Ydoncat);
set MyLib.NewFund end = last;
retain avgqtr1 0;
retain avgqtr2 0;
retain avgqtr3 0;
retain avgqtr4 0;
retain avgyear 0;
retain numObs 0;
avgqtr1 + qtr1;
avgqtr2 + qtr2;
avgqtr3 + qtr3;
avgqtr4 + qtr4;
avgyear + Year_don;
numObs + 1;
if last then
DO;
/* need to divide by number of observations to make these values the Arithmetic mean */
avgqtr1 / numObs;
avgqtr2 / numObs;
avgqtr3 / numObs;
avgqtr4 / numObs;
avgYear / numObs;
output;
END;
run;
title1 'Average Funds';
Proc print data=Mylib.fund_avg;
run;
When i run the program, this is the error the log reports:
74 if last then
75 DO;
76 avgqtr1 / numObs;
_______
180
77 avgqtr2 / numObs;
_______
180
78 avgqtr3 / numObs;
_______
180
79 avgqtr4 / numObs;
_______
180
80 avgYear / numObs;
_______
180
ERROR 180-322: Statement is not valid or it is used out of proper order.
I'd like to fix the error above, and make SAS print only the averages that I calculated in a single observation.
答案 0 :(得分:0)
您需要将计算分配给变量。
Avgqtr1 = avgqtr1 / numbObs;
请不要这样做。 使用proc表示或proc SQL。
Proc表示会生成一个列,但proc SQL可以直接生成该行。
Proc SQL;
Create table my_lib.fund_avg as
Select mean(qtr1) as avgqtr1,
mean(qtr2) as avgqtr2,
...
From my_lib.new_fund:
Quit;