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

Hi,  I have a quick macro question.  I have two groups (1 and 2) and all the variables in each group end in either a 1 or 2 (matching up to the group).

  

 

So I have this code- and I need all the var names to change to their relative number (eg, dsterm1_display or dsterm2_display) with the macro call.  But I'm getting conversion warnings in the log because of the number with character.  How can I use the number as a character here?

 Help is appreciated!!

 

%macro trt (new,data,t);

 

data &new (keep=&keep usubjid visit dsstdat dsscat dsstdatc dsterm_display dsaeno dscont_display dsdecod_display);
length &len dsscat $50.;
set &data;
by usubjid;
dscat="DISPOSITION EVENT";
dsscat='TREATMENT';

if dsterm&t_display ^=''  then do;
dsterm=dsterm&t_display;
DSDECOD=dsdecod&t_display;
end;
run;

 

%mend trt;

 

%trt (cb839_trt, eot1, 1);
%trt (cbz_trt, eot2, 2);

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

If I am understanding you properly, this is the fix to your code

 

if dsterm&t._display ^=' '  then do;
dsterm=dsterm&t._display;
DSDECOD=dsdecod&t._display;

If that's not it, SHOW US THE SASLOG.

--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

If I am understanding you properly, this is the fix to your code

 

if dsterm&t._display ^=' '  then do;
dsterm=dsterm&t._display;
DSDECOD=dsdecod&t._display;

If that's not it, SHOW US THE SASLOG.

--
Paige Miller
Tom
Super User Tom
Super User

All macro variables are text.  It looks like your real issue is that you wanted to reference the macro variable T, but instead you are referencing the macro variable T_DISPLAY.  You need to insert a period so that SAS knows that you want T and the the _ and other characters are not part of the macro variable name.

dsterm&t._display 

Note you should move the numeric suffix to the end of your newer variable name.  So instead of naming the varibale DSTERM1_DISPLAY name it DSTERM_DISPLAY1.

dsterm_display&t

Not only will that remove the possibility of confusion about the name of the macro variable you are referencing it will make it easier to use the variable in variable lists.

keep dsterm_display1 - dsterm_display9 ;

 

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
  • 2 replies
  • 774 views
  • 1 like
  • 3 in conversation