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!
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.
YES! Thank you so much!!!
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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.