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);
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.