Hello SAS community!
When I try to add two columns together SAS generates a missing value on the first record.
Here is the sample code I'm running using the SAS Help library:
data test;
sum=sum(vsp,pop);
keep sum vsp pop;
set sashelp.tourism;
run;
I am attempting to calculate a sum between two columns, I keep on getting a missing value for the first record of the sum column and the it shift the corresponding sum one record down. See below:
What I want is the sum between two columns all on each respective row:
sum | vsp | pop |
55.9253 | 1.2823 | 54.643 |
56.2308 | 1.2718 | 54.959 |
56.753 | 1.537 | 55.216 |
57.4111 | 1.9501 | 55.461 |
57.462 | 1.83 | 55.632 |
58.5406 | 2.6126 | 55.928 |
59.2325 | 3.1535 | 56.079 |
59.2831 | 3.0601 | 56.223 |
58.8326 | 2.5966 | 56.236 |
59.1075 | 2.8815 | 56.226 |
58.3674 | 2.1514 | 56.216 |
58.734 | 2.544 | 56.19 |
and so on...
Please help! I've tried using coalesce with the sum but all it did was is convert the missing value into a zero.
Thank you in advance
It is very hard for SAS to add values together BEFORE it actually HAS the values!
Fix the order of your statements so they make sense.
data test;
set sashelp.tourism;
sum=sum(vsp,pop);
keep sum vsp pop;
run;
Move the SET statement to above the SUM
It is very hard for SAS to add values together BEFORE it actually HAS the values!
Fix the order of your statements so they make sense.
data test;
set sashelp.tourism;
sum=sum(vsp,pop);
keep sum vsp pop;
run;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: