DATA Step, Macro, Functions and more

Invoking multiple macros

Reply
Occasional Contributor
Posts: 7

Invoking multiple macros

invoke_e macro,
i have this following code::

%MACRO GenerateVariables ;

%GLOBAL stUID Macro stMedInd stMCC stSex intAge intDur stPcode intIssueyr;

%END;

%GLOBAL N;

DATA _NULL_

SET Output.ULExtract&SYear END = LAST;

CALL SYMPUT(COMPRESS('stUID'||_N_), Polnum);

CALL SYMPUT(COMPRESS('Macro'||_N_), stMacroName);

CALL SYMPUT(COMPRESS('stMedInd'||_N_), MedInd);

CALL SYMPUT(COMPRESS('stMCC'||_N_), Uncd);

CALL SYMPUT(COMPRESS('stSex'||_N_), Mysex);

CALL SYMPUT(COMPRESS('intAge'||_N_), issage);

CALL SYMPUT(COMPRESS('intDur'||_N_), Duration);

CALL SYMPUT(COMPRESS('stPcode'||_N_), Plancode);

CALL SYMPUT(COMPRESS('intIssueyr'||_N_), efyr);

IF LAST THEN CALL SYMPUT('N',_N_);

RUN;

%MEND;

%MACRO RunCompositeQx;

%DO i = 1 %TO &N;

  %ULCompositeQx&&Macro&i(&&stUID&i,&&Macro&i,&&stMedInd&i,&&stMcc&i,&&stsex&i,&&intAge&i,&&intDur&i,&&stPcode&i,&&intIssueyr&i);

  PROC SQL NOPRINT;

   INSERT INTO Work.Output VALUES (&stPolnum, &CompQx1, &CompQx2);

  QUIT;

%END;

%MEND;

%MACRO FinalRun;

/*%DO j = 1 %TO &FracChunk;*/

%GenerateVariables;

%RunCompositeQx;

%MEND;

%FinalRun;run;

This is throwing up the following error:

 

ERROR 22-322: Syntax error, expecting one of the following: a quoted string, a numeric constant,

a datetime constant, a missing value, MISSING, NULL, USER.

and

LINE and COLUMN cannot be determined

WARNING: Apparent invocation of macro ULCompositeQx not resolved.

Could you please help me get this macro working please?

Trusted Advisor
Posts: 1,616

Re: Invoking multiple macros

You don't have defined a macro named %ULCompositeQx, so SAS doesn't know what to do when it encounters you calling this macro.

Occasional Contributor
Posts: 7

Re: Invoking multiple macros

No I have those. Just not part of this snippet of code.

Trusted Advisor
Posts: 1,616

Re: Invoking multiple macros

But SAS is telling you

WARNING: Apparent invocation of macro ULCompositeQx not resolved.

As far as I can see, you also don't have valid code for macro GenerateVariables. The line %end; just under the first %global causes this macro to fail.

Super User
Posts: 17,840

Re: Invoking multiple macros

Call execute could make this much simpler....

Occasional Contributor
Posts: 7

Re: Invoking multiple macros

Could you write some indicative codes please?  For call executing them

Super User
Posts: 17,840

Re: Invoking multiple macros

You'll have to probably redesign portion but this would be the gist of it:


data _null_;

set Output.ULExtract&SYear;

string = cats("%ULCompositeQx(", catx(",", stUID, Macro,stMedIni,stMcc,stsex,intAge,intDur,stPcode,intIssueyr), ");");

call execute(string);

run;


Occasional Contributor
Posts: 7

Re: Invoking multiple macros

thanks, but how will this work for 6 macros ULCompositeQx1-6.

Super User
Super User
Posts: 7,407

Re: Invoking multiple macros

data _null_;

     do i=1 to 6;

          call execute('%ULCompositeQx'||strip(put(i,best.))||' (paramters);');

     end;

run;

Perhaps post some test data, and required output as I fully agree with Reeza, you appear to be vastly over-complicating your code.  Check out arrays for example.

Super User
Posts: 17,840

Re: Invoking multiple macros

I doubt there's a good reason for 6 versions of a macro - make one version and pass the number in as a parameter to then do some other logic in the code.

Super User
Posts: 5,085

Re: Invoking multiple macros

Have you tried replacing this line:

%ULCompositeQx&&Macro&i

This might work better:

%unquote(%ULCompositeQx&&Macro&i)

It could be a matter of tokenization not being properly interpreted.

Occasional Contributor
Posts: 7

Re: Invoking multiple macros

i used this :

%MACRO RunCompositeQx;

%DO i = 1 %TO &N;

%unquote(%ULCompositeQx&&Macro&i)(&&stUID&i,&&Macro&i,&&stMedInd&i,&&stMcc&i,&&stsex&i,&&intAge&i,&&intDur&i,&&stPcode&i,&&intIssueyr&i);

  PROC SQL NOPRINT;

   INSERT INTO Work.Output VALUES (&stPolnum, &CompQx1, &CompQx2);

  QUIT;

%END;

%MEND;

but still got the following errors:

22: LINE and COLUMN cannot be determined.

ERROR 22-322: Syntax error, expecting one of the following: a quoted string, a numeric constant,

  a datetime constant, a missing value, +, -, MISSING, NULL, USER.

Super User
Posts: 5,085

Re: Invoking multiple macros

Then I would recommend getting rid of the macro language, to narrow down the error.

This is actually easier than it sounds.  Take a look at the MFILE and MPRINT combination of options.  They will let you save the code generated by the macro, in a separate file.  Then run the file which will contain the generated code but no macro language.  The error message you get will be much cleaner to interpret.

Good luck.

Super User
Super User
Posts: 7,407

Re: Invoking multiple macros

Precisely why I avoid macros:

%unquote(%ULCompositeQx&&Macro&i)(&&stUID&i,&&Macro&i,&&stMedInd&i,&&stMcc&i,&&stsex&i,&&intAge&i,&&intDur&i,&&stPcode&i,&&intIssueyr&i);

That to me is the epitome of obfuscation.  What is it your trying to achieve?  Post test data and example output. 

Occasional Contributor
Posts: 7

Re: Invoking multiple macros

I tried the Mprint and MFile options and there is a problem with the (%ULCompositeQx&&Macro&i)(&&stUID&i,&&Macro&i,&&stMedInd&i,&&stMcc&i,&&stsex&i,&&intAge&i,&&intDur&i,&&stPcode&i,&&intIssueyr&i
stement...

the demacroed code is %ULCompositeQx .(000123033 , ., ., ., ., 42, .,12985, 2001);

so its recognizing the variables properly but not the correct macro number...i have macros ULcomposite 1-6

Ask a Question
Discussion stats
  • 15 replies
  • 386 views
  • 2 likes
  • 5 in conversation