BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
stickm
Fluorite | Level 6

Hello, I am trying to sum two numeric variables on SAS university.

I am using the code:

income= sum(FA7D, MB11D);

run;

 

However, the results are not summing the numeric variables. I used the

proc print; command for my variables and this is what I am seeing...

 

Capture.JPG

 

Can anyone please tell me what I am doing wrong?

 

Thanks,

1 ACCEPTED SOLUTION

Accepted Solutions
stickm
Fluorite | Level 6

Thank you for taking the time to respond to my message. I made a mistake in another part of my code, and that was why the sum command wasn't working as intended. I didn't want to post the entire code because I thought it was too long. Next time I will make sure to post everything.

Thanks again

View solution in original post

8 REPLIES 8
Reeza
Super User

If you have N in your data your variables may not be numeric. 

 

If you're trying to get the sum of a column the SUM() function isn't correct, that calculates the SUM for a specific row. 

If you're trying to get the sum of a column use a Summary PROC such as PROC MEANS, SUMMARY or UNIVARIATE for starters.

 

Video tutorials are here:

video.sas.com 

 

And specifically calculating summary statistics is here:

http://video.sas.com/detail/videos/sas-analytics-u/video/3306906230001/summary-statistics-using-sas-...

 


@stickm wrote:

Hello, I am trying to sum two numeric variables on SAS university.

I am using the code:

income= sum(FA7D, MB11D);

run;

 

However, the results are not summing the numeric variables. I used the

proc print; command for my variables and this is what I am seeing...

 

Capture.JPG

 

Can anyone please tell me what I am doing wrong?

 

Thanks,


 

stickm
Fluorite | Level 6

Thank you for the quick reply.

 

I believe both variables are numeric. When I used the 

proc contents;

function it showed me:

 

1.JPG2.JPG

 

I am trying to create a new variable that combines the total value in each row for FA7D and MB11D.

Everything resource I have found has told me to use the newvariable=sum(var1, var2) command. However, when I perform it, it doesn't sum the values. It shows the new variable value as missing instead of being summed.

 

Thanks again,

art297
Opal | Level 21

I doubt if anyone can help unless you show the entire datastep you ran and post your dataset (not a picture of it)

 

Art, CEO, AnalystFinder.com

 

mkeintz
PROC Star

Is you use of the SUM function embedded in a condition step of your logic, i.e. in an "if" statement    or a do group triggered by an if statement?

 

Show us the log for a more precise answer.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
Shmuel
Garnet | Level 18

Post the full log of the run. I belirve the hint is there.

 

There is no syntax error in your code income = sum(FA7D, MB11D);

ballardw
Super User

Show your entire code. I do NOT believe that is only the result for the code snippet you have shown as SAS will convert character values to numeric and sum the result.

Example:

data junk;
   input x $ y $;
   z = sum(x,y);
datalines;
1 2
N 3
4 5
6 N
;
proc print;
run;

There will be notes in the log like:

 

NOTE: Character values have been converted to numeric values at the places given by:
      (Line):(Column).

saying the character variables were treated as numeric.

 

 

If the variables are truly numeric the only way to have N displayed would be to have the special missing .N (yes there is a period preceding the N) and the SUM will still work. HOWEVER if you used income = FA7D + MB11D; That would generate the output you show for Proc Print.

Perhaps the data step you used SUM in had another error and did not replace a data set created with the + sum for some reason. Which is why we say : Show the log of the data step with any messages. Paste into a code box opened with the forum {I} icon to preserve formatting of any error or warning messages.

stickm
Fluorite | Level 6

Thank you for taking the time to respond to my message. I made a mistake in another part of my code, and that was why the sum command wasn't working as intended. I didn't want to post the entire code because I thought it was too long. Next time I will make sure to post everything.

Thanks again

Reeza
Super User

Please mark this as resolved, you can use your last post as the correct solution.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 8 replies
  • 5146 views
  • 0 likes
  • 6 in conversation