Folks,
I'm having an issue with sum of function with SAS. For example the following code produces the correct output for some sample data.
DATA LIST;
INPUT X Y Z;
DATALINES;
1 2 3
4 5 6
;
run;
data i;
set list;
u=sum(of x y z);run;
However, when I attempt to run it with my own data what happens is that the variables which are on line 1 are summed, but the total of the new variable is pushed onto line 2.
For instance what's happening is
DATA LIST;
INPUT X Y Z;
DATALINES;
1 2 3
4 5 6
;
run;
data i;
set list;
u=sum(of x y z);run;
x y z u
1 2 3 .
4 5 6 6
. . . 15
Has anyone any idea why this is happening?
There's something else happening (the code you ran is not exactly what you posted).
Because this code:
DATA LIST;
INPUT X Y Z;
DATALINES;
1 2 3
4 5 6
;
run;
data i;
set list;
u=sum(of x y z);
run;
proc print data=i noobs;
run;
gives me this result:
X Y Z u 1 2 3 6 4 5 6 15
Are you doing these calculations in the same step that you read an external file? It may be that the data you think are "blanks" are actually getting interpretted as end of line for the input.
It never hurts to show the exact code you ran from the log with any messages or notes.
No, it won't work like that. I suspect the program that you actually ran switched the order of two statements:
data i;
u = sum(of x y z);
set list;
run;
Even that will give you only two observations (not three), but it will shift the values of U by one observation.
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.