Reputation: 3
I have a situation where I need to assign a table name with a macro variable whose value is derived from another macro variable.
However, the generated code in macro uses the derivation formula rather than the derived value itself.
%macro testing;
%let n=2;
%let k=&n-1;
%let opp=&k;
PROC SQL;
CREATE TABLE WORK.TABLE_&opp AS
SELECT * from WORK.SOURCETABLE;
QUIT;
%mend;
%testing
This resulted in error as the code generated
NOTE: Line generated by the macro variable "OPP".
34 WORK.TABLE_2-1
_
22
200
ERROR 22-322: Syntax error,
But I am expecting the resultant table will be named as WORK.TABLE_1 instead of WORK.TABLE_2-1.
So how can I force SAS to identify variable opp=1 rather than opp=2-1?
Thank you
Upvotes: 0
Views: 411
Reputation: 335
Try using %eval as shown under:
%macro testing;
%let n=2;
%let k=&n-1;
%let opp=%eval(&k);
PROC SQL;
CREATE TABLE WORK.TABLE_&opp AS
SELECT * from WORK.SOURCETABLE;
QUIT;
%mend;
%testing
Upvotes: 2