I have used the following code to define use disorder if 2 or more questions are answered as yes. This statement works for this purpose.
data mergeTOB2; set mergeTOB1;
array num{*} CIINTERF--CIPROBLM;
TOBDORD = sum (of num(*)) ge 2;
run;
How can i modify this statement to define mild and moderate disorder, where sum of ge 2 but lt 3 is mild and ge 4 is moderate?
So it can be only mild and moderate, or?
less than 2 = no disorder; 2 to 3 = mild disorder; 4 or more = moderate/severe
Maybe in SQL you could assign three different values with a single CASE statement. But in a DATA step you will need two variables:
data mergeTOB2;
set merge TOB;
array num {*} CIINTERF--CIPROBLM;
TOBDORD = sum(of num{*});
if tobdord >= 4 then result = "moderate/severe";
else if tobord = 3 then result = "mild";
else result = "no disorder";
run;
You could consider dropping TOBORD once RESULT is created. Alternatively, you could skip creating RESULT entirely and just let TOBORD be your new variable. When it comes time to print, you could add a format that translates numeric values into descriptive strings, such as:
proc format;
value result low-2 = "no disorder"
3 = "mild"
4-high = "moderate/severe";
run;
Another variation: it's not clear if you want to get rid of the observations with counts of 2 or less. The last ELSE statement could become (if needed):
else delete;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.