Hi! I'd like to know if there is a way to do an array / do loop checking for multiple values.
I have this code, but I'd like to check is any DX1-DX10 start with these values: 7707, 748, 505
data OP_Exlusion5;
set asthma.OPssn_JoinFY14nd;
array dx(*) DX1-DX10;
do i= 1 to dim(dx);
if dx(i)=: '7707' then do;
output;
end;
end;
run;
When I include all the values in the if statement, I am getting an error. Do I need multiple IF statements?
Thanks!
If I understand your question correctly, you could try this:
data OP_Exlusion5;
set asthma.OPssn_JoinFY14nd;
array dx(*) DX1-DX10;
do i= 1 to dim(dx);
if dx(i)=: '7707' or dx(i)=: '748' or dx(i)=: '505' then do;
output;
return;
end;
end;
run;
What error do you get? Even if there was no error it will create multiple records if more than one DX variables had one of the values you listed. To avoid this situation create a flag in the loop and then use the flag to output subset of the data.
If I understand your question correctly, you could try this:
data OP_Exlusion5;
set asthma.OPssn_JoinFY14nd;
array dx(*) DX1-DX10;
do i= 1 to dim(dx);
if dx(i)=: '7707' or dx(i)=: '748' or dx(i)=: '505' then do;
output;
return;
end;
end;
run;
Also note, the IN comparison also knows how to use a colon, and understands that arguments may be of different lengths:
if dx{i} in : ('7707', '748', '505') then do;
Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.
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.