Reputation: 49
I am trying to pass numeric variables into this macro. I am able to pass it through the KEEP and SET statements, but when it gets to the RENAME statement I get these errors:
ERROR: Variable '2013'n is not on file WORK.'2013'n.
ERROR: Invalid DROP, KEEP, or RENAME option on file WORK.'2013'n.
%macro step2(year,cwyear);
TITLE; FOOTNOTE;
DATA WORK._EG_CFMT;
LENGTH label $ 9;
SET WORK."&year."n (KEEP="&year."n "&cwyear."n RENAME=("&year."n =start "&year."n =label)) END=__last;
RETAIN fmtname "cw&year."n type "C";
end=start;
RUN;
%mend step2;
When I change the double quotes around &year. to single quotes, like this:
SET WORK.'&year.'n (KEEP="&year."n "&cwyear."n RENAME=("&year."n =start "&year."n =label))
I get this error:
ERROR: File WORK.'&YEAR.'n.DATA does not exist.
When I change back to all double quotes and remove the n's, I get the following error:
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, ;, CUROBS, END, INDSNAME, KEY, KEYRESET, KEYS, NOBS, OPEN, POINT, DATA, LAST, NULL.
How do I make this work?
Thanks for the help!
Upvotes: 2
Views: 6716
Reputation: 63434
You need to have double quotes AND the n. Name literals can use single or double quotes just like any other string. Single quotes won't resolve macro variables inside of them, double will.
Example:
options validvarname=any;
options validmemname=extend;
data '2015'n;
'2015'n = 5;
run;
%macro do_something(year=);
data work.want;
set "&year."n(rename="&year."n = start);
run;
%mend do_something;
%do_something(year=2015);
Upvotes: 5