BookmarkSubscribeRSS Feed
gauravkodmalwar
Calcite | Level 5

************ MACRO code **********

%macro preRequisite(parStartDate=,parEndDate=);

options metaserver="servername" metaport=8561 metauser="sasadm@saspw" metapass="password" metarepository="Foundation";

proc sql;

/* some SQL code here*/

quit;

%mend preRequisite;

************ MACRO code **********


************ ERROR ************

76   %preRequisite(parStartDate=&varStartDate.,parEndDate=&varEndDate.);

MLOGIC(PREREQUISITE):  Parameter PARSTARTDATE has value 03/01/2012

MLOGIC(PREREQUISITE):  Parameter PARENDDATE has value 03/31/2012

NOTE: Line generated by the invoked macro "PREREQUISITE".

1      options metaserver="servername" metaport=8561 metauser="sasadm@saspw"

                         -

                         22

                         200

ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, (, /, ;, _DATA_,

              _LAST_, _NULL_.

ERROR 200-322: The symbol is not recognized and will be ignored.

1  !   options metaserver="servername" metaport=8561 metauser="sasadm@saspw"

                                                             --------                --------

--------------

                                                             22                      22


************ ERROR ************

16 REPLIES 16
gergely_batho
SAS Employee

Hi,

Very strange behaivior. For me this code is working.

I hope, this line: "   ************ MACRO code **********   "   is NOT part of the code! (It makes also the next line - the macro header - a comment, until the semicolon. )

It is is, remove it, or replace it with "  /*********** MACRO code *********/   "

gauravkodmalwar
Calcite | Level 5

Hi Gergely,

Yes, it's not part of sas code. I added it here, just to segregate between logs and sas code.

Thanks,

Gaurav

gergely_batho
SAS Employee

Does the macro compile without errors? Turn on these otions:

options mprint mlogic symbolgen mcompilenote=all;

gauravkodmalwar
Calcite | Level 5

Yes, there is no error at compile time of sas macro. There is error when your provided command added in sas macro. Error arrow was pointing at mcompilenote=all, I also tried with double quotes around all value (like mcompilenote="all") but still same error.

NOTE: Line generated by the invoked macro "PREREQUISITE".

1      options mprint mlogic symbolgen mcompilenote=all; options metaserver="servername"

                                                   -

                                                   22

                                                   200

1  ! metaport=8561 metauser="sasadm@saspw" metapass=XXXXXXXXXXX metarepository="Foundation";

ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, (, /, ;, _DATA_,

              _LAST_, _NULL_.

ERROR 200-322: The symbol is not recognized and will be ignored.

91   run;

NOTE: The SAS System stopped processing this step because of errors.

WARNING: The data set WORK.OPTIONS may be incomplete.  When this step was stopped there were 0

         observations and 0 variables.

WARNING: Data set WORK.OPTIONS was not replaced because this step was stopped.

WARNING: The data set WORK.MPRINT may be incomplete.  When this step was stopped there were 0

         observations and 0 variables.

WARNING: Data set WORK.MPRINT was not replaced because this step was stopped.

WARNING: The data set WORK.MLOGIC may be incomplete.  When this step was stopped there were 0

         observations and 0 variables.

WARNING: Data set WORK.MLOGIC was not replaced because this step was stopped.

WARNING: The data set WORK.SYMBOLGEN may be incomplete.  When this step was stopped there were 0

         observations and 0 variables.

WARNING: Data set WORK.SYMBOLGEN was not replaced because this step was stopped.

WARNING: The data set WORK.MCOMPILENOTE may be incomplete.  When this step was stopped there were 0

         observations and 0 variables.

WARNING: Data set WORK.MCOMPILENOTE was not replaced because this step was stopped.

WARNING: The data set WORK.ALL may be incomplete.  When this step was stopped there were 0

         observations and 0 variables.

WARNING: Data set WORK.ALL was not replaced because this step was stopped.

NOTE: DATA statement used (Total process time):

      real time           0.02 seconds

      cpu time            0.01 seconds

Reeza
Super User

What happens if you remove the options statement, does the macro execute appropriately?

gergely_batho
SAS Employee

This is something very strange. The Warning messages suggest, that options names became dataset name.

Are you calling the macro in an open code? It seems you called it from the inside a data step!!  This could be the explanation of the error messages.

By the way, do not place the options statement inside the macro. Just run it once, outside of the macro.

gauravkodmalwar
Calcite | Level 5

If I remove options from macro then macro runs fine and if I run only options sentence then inside macro by using F3, it also runs fine without any issue. You are right, I am calling it from data step. I used data step because I was calling macro earlier by using call Execute but now I changed my mind to directly call macro. Now facing another issue but not related to this issue. Thanks Gergely & Reeza.

gergely_batho
SAS Employee

call execute('some string') puts 'some string' on the input stack - during the execution phase of data step. So if 'some string' contains SAS statements they are executed after the data step has finished. (Exception to it are macro statements, which are executed immediatel.)

When you call a macro, the contents of the macro are unfolded immediately, and this is done even before the compillation phase of the data step.

In case the macro contatains SQL or options statement, it's like puting SQL code inside data step. This is of course not possible.

You should call this macro simply from open code.

gauravkodmalwar
Calcite | Level 5

Thanks Kurt, you are right. It solved that error but now failing at next step. It's not able to identify another macro, may be because credentials provided in options statement is not effectively red.

162  %mend preRequisite;

NOTE: The macro PREREQUISITE completed compilation without errors.

      11 instructions 340 bytes.

163  data _null_;

164  %let varStartDate =03/01/2012;

165  %let varEndDate =03/31/2012;

166  %preRequisite(parStartDate=&varStartDate.,parEndDate=&varEndDate.);

MLOGIC(PREREQUISITE):  Beginning execution.

SYMBOLGEN:  Macro variable VARSTARTDATE resolves to 03/01/2012

SYMBOLGEN:  Macro variable VARENDDATE resolves to 03/31/2012

MLOGIC(PREREQUISITE):  Parameter PARSTARTDATE has value 03/01/2012

MLOGIC(PREREQUISITE):  Parameter PARENDDATE has value 03/31/2012

MPRINT(PREREQUISITE):   options metaserver="servername" metaport=8561 metauser="sasadm@saspw"

metapass="Password1" metarepository="Foundation";

NOTE: Line generated by the invoked macro "PREREQUISITE".

1      %anothermacro;

-

180

WARNING: Apparent invocation of macro anothermacro not resolved.

MPRINT(PREREQUISITE):   %anothermacro;

MLOGIC(PREREQUISITE):  Ending execution.

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

167  run;

NOTE: The SAS System stopped processing this step because of errors.

NOTE: DATA statement used (Total process time):

      real time           0.01 seconds

      cpu time            0.00 seconds

gergely_batho
SAS Employee

Hi,

No, it is not because of credentials. That macro is not (yet) defined in this SAS session.

You should run the macro definition. Something like this one:  %macro anothermacro.....    %mend;

Or this %anothermacro is an aoutocall macro. In this case the macro definition is stored on the server. Check the autosource and  sasautos= system option.

Or this %anothermacro is a precompiled macro. Check the mstored and sasmstore=system options.

Was the call of %anothermacro  succesfull in other cases (other programs)?

Message was edited by: Gergely Bathó

gauravkodmalwar
Calcite | Level 5

Actually if I call first macro in same file after %mend then %anothermacro is called smoothly without any issue. Like following:

%macro preRequisite(parStartDate=,parEndDate=);

options metaserver="servername" metaport=8561 metauser="sasadm@saspw" metapass="password" metarepository="Foundation";

%anothermacro;

%mend preRequisite;

/* call the first macro */

%let varStartDate =03/01/2012;

%let varEndDate =03/31/2012;

%preRequisite(parStartDate=&varStartDate.,parEndDate=&varEndDate.);

But when I call same macro from another file, where I already included path of first macro into the sasautos then it throws error:

! metarepository="Foundation";  %anothermacro;

                                   -

                                   180

WARNING: Apparent invocation of macro anothermacro not resolved.

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

gergely_batho
SAS Employee

When a macro like this compiles:

%macro xxx(<parameters>);

<statements>

%anothermacro;

%mend xxx;

it doesn't mean %anothermacro  exists. The existence of %anothermacro is revealed only when you call the %xxx macro.

What happens if you just call %anothermacro  from open code?

%anothermacro;

How do you "include path of first macro into the sasautos"? With a statment like this?

options sasautos=(path1, path2);

gauravkodmalwar
Calcite | Level 5

Gergely,

I use following code to include xxx macro into my code where I am calling macro and xxx macro file is saved at same path.

%let urmacros='D:\spa\windows CI\common';

options sasautos=(&urmacros.);

If I call %anothermacro then it works fine but I need to use path of %anothermacro in the code. Problem is appearing when I call xxx macro and xxx macro calls anothermacro. Surprisingly, if I call xxx macro from it's own file (after %mend by using %xxx()) then it works fine but it doesn't work fine when  I call it from another code file.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 16 replies
  • 1423 views
  • 0 likes
  • 5 in conversation