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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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