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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
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!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.