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;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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