Hi there,
I would like to ask for assistance on how to write the SAS code to count number of variables with values.
I have the following variables in my table : Diagnosis1,Diagnosis2, Diagnosis3, Diagnosis4, Diagnosis5
And I would like to count the number of variables only if they have a value.
For example, if I only have values for Diagnosis1 , Diagnosis2 and Diagnosis3 , and there are NO values for Diagnosis4 and Diagnosis5 , my diagnosis count will be = 3 .
Greatly appreciate any assistance.
Thank you in advance.
In a SAS data step, use the N() function, something like this will work:
data two;
set one;
count=n(of diagnosis1-diagnosis5);
run;
In a SAS data step, use the N() function, something like this will work:
data two;
set one;
count=n(of diagnosis1-diagnosis5);
run;
Are your variables numeric or character?
If the values are numeric you can use the N function
diagnosis_count = n (diagnosis1,diagnosis2,diagnosis3,diagnosis4,diagnosis5);
If the values are character, you can use the CMISS() Function to count the missings and then the number of non-missing is
count = 5 - cmiss(of diagnosis1-diagnosis5);
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.