BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
gstover
Fluorite | Level 6

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.

1 ACCEPTED SOLUTION

Accepted Solutions
gstover
Fluorite | Level 6

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! 

 

View solution in original post

6 REPLIES 6
SASKiwi
PROC Star

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;

 

gstover
Fluorite | Level 6

Thank you! This works great, however I would like only one ED_OUD_flag, is there a way to do this?

SASKiwi
PROC Star

@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?

gstover
Fluorite | Level 6
Correct. 1 if it hits the format, or 0 if it's not in the format
SASKiwi
PROC Star

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;
gstover
Fluorite | Level 6

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! 

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 2018 views
  • 3 likes
  • 2 in conversation