DATA Step, Macro, Functions and more

Macro cycle 1 is fine, fails on cycle 2

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 128
Accepted Solution

Macro cycle 1 is fine, fails on cycle 2

Hi,

 

I'm trying to run this code and it runs through the mod=1 cycle just fine.  No errors.  But the minute it gets to %mod(mod=2), then it says:

ERROR: All positional parameters must precede keyword parameters.
41         %mod(mod=2);

/*Add three variables from the PayerOnESRD dataset to the ALL $Ds and split out for M and N.*/
%macro mod(mod=);
    %macro splitd(lib=,type=,chgdt=,chgtype=);
    %do year4=&start. %to &end.;
        %let yr = %eval(%substr(&year4,3,2));

        proc sql;
            create table &lib..inc_&mod.y&yr. as
            select a.*,
                    b.esrdpaystat as paystat,
                    b.&chgdt. as paychgdt,
                    b.&chgtype. as paychgtype
            from ialld.in_&mod.y&yr. a left join pay.payeronesrd b
            on a.kecc_id=b.kecc_id
            where ESRDM="&type.";
        quit;
    %end;
    %mend splitd;
    %splitd(lib=imd,    type=M,    chgdt=M2NMChgDt,    chgtype=m2nmchgtype);
    %splitd(lib=inmd,    type=NM,chgdt=NM2MChgDt,    chgtype=nm2mchgtype);
%mend;
%mod(mod=1);
%mod(mod=2);
%mod(mod=5);
%mod(mod=6);

 

 

 

 

 


Accepted Solutions
Solution
‎03-22-2016 03:06 PM
Frequent Contributor
Posts: 128

Re: Macro cycle 1 is fine, fails on cycle 2

Weird, it didn't crash this time.

 

Cripes.  Ok, thanks!

View solution in original post


All Replies
Super User
Posts: 5,085

Re: Macro cycle 1 is fine, fails on cycle 2

Absolute speculation ...

 

Purely a wild guess ...

 

It looks like you are willing to use a system of defining macros within another macro (usually frowned upon!).  Also, I imagine that you have simplified your code to make your question manageable in size.  So, what I suspect ...

 

Within your system of macros calling macros, one of the macros redefines the meaning of %MOD.  So the second time, it means something totally different than what it did the first time.

Frequent Contributor
Posts: 128

Re: Macro cycle 1 is fine, fails on cycle 2

[ Edited ]

I nest macros quite often....  *looks around questioningly...*

 

And no, it was a straight copy paste of the code.

 

What do you mean im redefining the meaning of %mod.  Where?  It's just used for the naming of files. I did re-try it, by changing the outer macro to %modx instead, wondering if using the same name for the macro and the macro var was causing it, but i still got the same error.

 

 EDIT: The only part of the actual code i left out from the above copy were the values of &start and &end and the libnames.  1978 and 2015.

SAS Employee
Posts: 6

Re: Macro cycle 1 is fine, fails on cycle 2

I ran the code and was unable to replicate your error.  Could you run it again in a new SAS session and attach the new log?

Solution
‎03-22-2016 03:06 PM
Frequent Contributor
Posts: 128

Re: Macro cycle 1 is fine, fails on cycle 2

Weird, it didn't crash this time.

 

Cripes.  Ok, thanks!

Trusted Advisor
Posts: 1,115

Re: Macro cycle 1 is fine, fails on cycle 2

Hi @MeganE,

 

Normally, this error message occurs only if you specify something in a macro call which SAS interprets as a positional parameter.

 

Examples:

%mod(mod=1,2);
%mod(mod=1,);

Typically in such cases, people try to pass a value containing a comma to a keyword parameter and forget to quote the comma or the entire value (e.g. by using the %STR function).

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 255 views
  • 0 likes
  • 4 in conversation