BookmarkSubscribeRSS Feed
GregG
Quartz | Level 8

In the following example, because of missing numeric data, using the plus sign to add horizontally across variables results in an overall missing value as well. However, using SAS's SUM function will display what I am expecting.

Because of that, in what circumstances if any would using a plus sign be more beneficial?

Thank you for your time.

data test;

    x = 10;

    y = .;

    z = 7;

    test1 = x+y+z;

    test2 = sum(x,y,z);

    label test1='x+y+z' test2='sum(x,y,z)';

run;

proc report data=test nowd;

run;

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hi,

One benefit of sum() is that you can use arrays:

data want;

     array col{*};

     result=sum(of col{*});

run;

Above assumes variables called col1-colx, not checked the code. 

Then of course the missing to number addition, sometimes you want to get a result even if . + 2 = .

Tom
Super User Tom
Super User

You said it yourself already. When you WANT the sum to be missing when any of the individual terms are missing.

GregG
Quartz | Level 8

Thank you. I just wanted to make sure I wasn't missing something crucial.

If I want to treat missing values essentially as 0s, then I can use SUM and be fine.

If I want to account for missing values, then I would use +.

Thanks again.

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 3 replies
  • 718 views
  • 6 likes
  • 3 in conversation