Lyle
Lyle

Reputation: 229

Macro variable wont resolve with underscores

Having an issue when trying to get macro variables to resolve inside a macro definition when using underscores. I would like to keep the naming convention I have here but need the macro variables to resolve to do so. What am I missing?

%macro mymacro(dd=,mm=,yy=,dnr=,dma=);
.
.
.

%if dnr = 1 %then %let dnrname=est;
%if dnr = 2 %then %let dnrname=cen;
%if dnr = 3 %then %let dnrname=mtec;
%if dnr = 4 %then %let dnrname=pac;
%if dnr = 5 %then %let dnrname=mtwp;

data setoff_&dnrname._&dma._&mm.&dd.&yy.;
    set restart_no retimed one_min_durations;
run;
.
.
.
%mend mymacro;

The error looks like:

NOTE: Line generated by the invoked macro "SETOFF".
89      data setoff_&dnrname._&dma._&mm.&dd.&yy.;     set restart_no retimed one_min_durations;
                    -
                    22
                    200
89  ! run;  proc sort data = setoff_&dnrname._&dma._&mm.&dd.&yy.;     by &dims_list. sid; run;

ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, (, /, ;,
              _DATA_, _LAST_, _NULL_.

Upvotes: 0

Views: 728

Answers (1)

Joe
Joe

Reputation: 63424

%if dnr = 1 %then %let dnrname=est;

This is the problem. dnr never equals 1. You are missing the ampersand.

Upvotes: 4

Related Questions