BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
mreynaud
Obsidian | Level 7

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:

mreynaud_0-1652293378606.png

What I want is the sum between two columns all on each respective row: 

sumvsppop
55.92531.282354.643
56.23081.271854.959
56.7531.53755.216
57.41111.950155.461
57.4621.8355.632
58.54062.612655.928
59.23253.153556.079
59.28313.060156.223
58.83262.596656.236
59.10752.881556.226
58.36742.151456.216
58.7342.54456.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

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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;

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

Move the SET statement to above the SUM

--
Paige Miller
Tom
Super User Tom
Super User

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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 2150 views
  • 1 like
  • 3 in conversation