Hi,
I also want to include a condition that if any of the these codes are not present then Arrhythemia='None';
I tried to use NOT IN condition and i dont get it right??
Could you help resolve.
Thanks
You need to look up if/else if/else operations.
data diag_array;
set daig_cohort;
array diag(50) dx1-dx50;
do i=1 to 35;
if diag(i) EQ '427.31' THEN Arrhythemia='flu1';
else if diag(i) EQ '427.32' THEN Arrhythemia='flu2';
else if diag(i) in('427','427.0','427.2','427.3','427.60', '427.61', '427.8', '427.81', '427.89', '427.9') THEN Arrhythemia='Other';
else Arrhythemia='None';
end;
run;
You need to look up if/else if/else operations.
data diag_array;
set daig_cohort;
array diag(50) dx1-dx50;
do i=1 to 35;
if diag(i) EQ '427.31' THEN Arrhythemia='flu1';
else if diag(i) EQ '427.32' THEN Arrhythemia='flu2';
else if diag(i) in('427','427.0','427.2','427.3','427.60', '427.61', '427.8', '427.81', '427.89', '427.9') THEN Arrhythemia='Other';
else Arrhythemia='None';
end;
run;
As Reeza indicated, you would do well to learn the ELSE statement. But your problem lies in another area.
You only have 1 variable you are setting, but you examine 35 diagnosis codes. What should happen if dx1='427.31' and dx2='427.32' and dx3='555'? That's not a programming issue, that's a matter of thinking through the result you would like to achieve.
Each time through your DO loop, you overwrite the value of your new variable. So in your code, dx35 is the only one that matters. Its value is the only one determining your new variable.
Good luck.
Responding to your original code, looks like you would like to parse across 50 columns(diag) and thru 1000 rosw to set condition for Arrhythemia.
Heres my quick solution. Giv it a shot -
data diag_array;
set daig_cohort;
eligdiag = 0;
array diag(50) dx1-dx50;
do i=1 to 50;
IF diag(i) EQ '427.31' THEN DO;
eligdiag = 1;
Arrhythemia='flu1';
END;
ELSE IF diag EQ '427.32' THEN Arrhythemia='flu2' THEN DO;
eligdiag = 1;
Arrhythemia='flu2';
END;
ELSE IF diag in('427','427.0','427.2','427.3','427.60', '427.61', '427.8', '427.81', '427.89', '427.9') THEN DO;
eligdiag = 1;
Arrhythemia='Other';
END;
ELSE DO;
eligdiag = 0;
Arrhythemia='None';
END;
IF eligdiag = 1 then leave;
end;
DROP eligdiag;
run;
the LEAVE statement is the key here.
Gud Luk!
Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.
Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.