BookmarkSubscribeRSS Feed
RNscientist
Calcite | Level 5

Hello.

 

I am trying to sum 5 columns to get a total score for each participant (row); however, I don't want SAS to sum rows with missing data, but I also don't want to delete those participants as I have data for them on a different variable.

 

So far I have tried 

 

data want;
set have;
sum_W1= sum(var1, var2, var3, var4, var5);

run;

 

however this sums across the row even if I'm missing data in 4 out of the 5 columns. 

 

For instance 

var 1  var 2 var 3  var 4   var 5

.            .            3        .             .

 

This is giving me a total score of 3 but I want it to read . 

 

Thanks for any help! 

3 REPLIES 3
Astounding
PROC Star

This might suit what you are asking for:

if n(of var1-var5) = 5 then sum_W1=sum(of var1-var5);

Make sure you include that key word "of".  Without it, SAS will compute var1 minus var5.

RNscientist
Calcite | Level 5

YES! Thank you so much!!! 

ballardw
Super User

Admittedly long to type for many variables but the + operator will return missing if any of the variables are missing:

 

sum_W1= var1+ var2+ var3+ var4+ var5;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 3 replies
  • 1196 views
  • 2 likes
  • 3 in conversation