I am trying to create a macro surrounding the following code:
if put(dx1,$oudfmt.) = '1'
then
ED_OUD_flag = 1 ;
else
ED_OUD_flag = 0 ;
I have 87 diagnoses codes and want to create a macro that passes the 87 variables and set my flag based on a format. I have tried numerous things and am a little weary right now, and help is greatly appreciated.
Wanted to share my final successful code.
array dx (*) dx1 - dx80;
do i = 1 to dim(dx);
if (put(dx(i),$odfmt.) = '1')
then ED_OD_FLAG = 1 ;
end ;
This worked very well - thank you so much for your help!
No macro is needed. Use arrays instead:
data want;
set have;
array dx (*) dx1 - dx87;
array ED_OUD_flag (*) ED_OUD_flag1 - ED_OUD_flag87;
do i = 1 to dim(dx);
ED_OUD_flag(i) = (put(dx(i),$oudfmt.) = '1');
end;
run;
Thank you! This works great, however I would like only one ED_OUD_flag, is there a way to do this?
@gstover - So what is your logic then? Do all 87 dx variables have to be equal to 1 to set ED_OUD_flag to 1?
Try this (untested):
data want;
set have;
array dx (*) dx1 - dx87;
do i = 1 to dim(dx);
ED_OUD_flags + (put(dx(i),$oudfmt.) = '1');
end;
ED_OUD_flag = (ED_OUD_flags = 87);
run;
Wanted to share my final successful code.
array dx (*) dx1 - dx80;
do i = 1 to dim(dx);
if (put(dx(i),$odfmt.) = '1')
then ED_OD_FLAG = 1 ;
end ;
This worked very well - thank you so much for your help!
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.