SAS macro questions

Reply
Regular Contributor
Posts: 173

SAS macro questions

Hello Everyone,

 

I am trying to pass a macro variable (List1) into a sas Macro (cust).  When I run the code below I get an error:

What am I doing wrong??

 

SYMBOLGEN: Macro variable MNTH_1 resolves to 201301

SYMBOLGEN: Macro variable LIST1 resolves to 'AE','AF','AG','AO','AR','BH'

NOTE: Line generated by the macro variable "LIST1".

1344 'AE','AF','AG','AO','AR','BH'

----

180

ERROR: All positional parameters must precede keyword parameters.

ERROR 180-322: Statement is not valid or it is used out of proper order.

 

 

 

 

Rsubmit;

%LET list1 =%unquote(%nrbquote('AE','AF','AG','AO','AR','BH'));

%LET MNTH_1 = 201301;

Endrsubmit;

Rsubmit;

%MACRO cust(data=, month=, var1=, ls=);

PROC SQL;

CREATE TABLE cust_&month. AS

SELECT T1.cust_KEY

, T1.open_DATE

, SUM(CASE WHEN &var1. >= &Default_Value. and OPP_COUNTRY_CD IN (&HIGH_RISK_CTRY_LIST_201412.) THEN 1 ELSE 0 END) AS NUMBER_OCCURENCE

FROM &data._&month. AS T1

GROUP BY 1,2;

QUIT;

%MEND;

%cust(data=af, month=&MNTH_1., var1=ACCT_CURRENCY_AMOUNT, ls=&list1. );

Endrsubmit;

Grand Advisor
Posts: 17,405

Re: SAS macro questions

I don't know the answer to your question, but I do know that the comma's between the values are not needed for the IN comparison so if possible, you could remove them.  

Grand Advisor
Posts: 10,229

Re: SAS macro questions

The cause is in this line:

%cust(data=af, month=&MNTH_1., var1=ACCT_CURRENCY_AMOUNT, ls=&list1. );

the macro variable &list is resolved so the call is being treated as:

 

%cust(data=af, month=201301, var1=ACCT_CURRENCY_AMOUNT, ls='AE','AF','AG','AO','AR','BH');

so the 'AF' is treated as a positional parameter due to the presence of the commas.

 

using ls= %quote(&list1.) may fix the problem if you really do need the commas in the value.

Respected Advisor
Posts: 4,995

Re: SAS macro questions

It's a mistake to use %unquote outside of the macro, before passing the value of &LIST1.  Instead, use just %nrbquote.

 

INSIDE the macro, you can add:

 

%let ls = %unquote(&ls);

 

Truthfully, though, I don't see where you are using &LS at all.  You could just drop it from the macro definition (unless you just showed us an abbreviated version of the macro).

Ask a Question
Discussion stats
  • 3 replies
  • 355 views
  • 0 likes
  • 4 in conversation