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);
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.
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.
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 ;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.