Hello expert SAS data management coders,
I have several dichotomous variables indicating the presence of clinical symptoms (i.e. cough, fever, etc) in an array. I would like to know if patients had "only cough," "only fever," etc. I have put some simplified, example code below with what I would like to happen in [brackets].
Hopefully this is a simple question, but if it is complicated, I can look at other routes. But I have had this question in general for a while now and so figured I would go ahead and ask. None of the references I can find on arrays seem to address this specific question.
Thank you in advance for your assistance.
Jonathan
array x {*} cough malnutrition fever lethargy;
array y {*} cough_only malnutrition_only fever_only lethargy_only
do i=1 to dim(x);
if x{i}=1 and [all other variables in the array equal 0] then y{i}=1;
else y{I}=0;
end; drop i;
if x{1}=1 and sum(of x{*})=1 then cough_only=1;
if x{2}=1 and sum(of x{*})=1 then malnutrition_only=1;
Or you could do this in a loop where instead of cough_only=1 you have y{1}=1
if x{1}=1 and sum(of x{*})=1 then cough_only=1;
if x{2}=1 and sum(of x{*})=1 then malnutrition_only=1;
Or you could do this in a loop where instead of cough_only=1 you have y{1}=1
Perfect - thanks so much! Didn't know about the {*}.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.