Hi
I'm working with a health survey data with twelve (12) columns/variables asking participants if they have different chronic health conditions. E.g.
Do you have Asthma: 1='Yes' 2='No' 6='Don't know' 7='Refusal'
Do you have hypertension: 1='Yes' 2='No' 6='Don't know' 7='Refusal'
I'm only interested in the number of health conditions that each participant has, so I'd like to create a new variable that extracts and sum all the 'Yes' and drop the other 12 variables.
I hope this makes sense; still new to SAS
Thank you!
For an accurate answer, you need to supply a bit more information. What are the names of the 12 variables? What values do they take on? For example, are they numeric with possible values 1, 2, 6, or 7?
Here's a reasonable guess as to what the programming might look like.
data want;
set have;
array conditions {12} cond1 - cond12;
n_conditions=0;
do i=1 to 12;
if conditions{i} = 1 then n_conditions + 1;
end;
run;
Until we know more about how the analysis would proceed, I would advise against dropping any variables at this point.
Thank you and yes, the columns are numeric variables with possible values of 1, 2, 6 & 7 with 1=Yes, 2=No etc. and I wanted to count the 1s
Something like this:
count of "1"
ID Col1 Col2 Col3 Col4 Col5 Col6 Col7 Col8................WANT
152 1 0 1 0 1 9 1 7 4
153 0 0 7 7 1 9 0 9 1
154 1 9 1 9 9 0 0 9 2
155 7 1 9 1 9 1 1 9 4
156 9 0 0 9 0 0 0 0 0
157 9 7 9 0 7 1 0 0 1
I found this in another thread which helped
data want; set have; countval = countc(cats(of col1-col13),'1'); run;
Thanks again
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.