Help using Base SAS procedures

Syntax error while providing options in macro, I also tried %options since options used inside macro but no luck

Reply
Contributor
Posts: 28

Syntax error while providing options in macro, I also tried %options since options used inside macro but no luck

************ 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 ************

SAS Employee
Posts: 340

Re: Syntax error while providing options in macro, I also tried %options since options used inside macro but no luck

Posted in reply to gauravkodmalwar

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 *********/   "

Contributor
Posts: 28

Re: Syntax error while providing options in macro, I also tried %options since options used inside macro but no luck

Posted in reply to gauravkodmalwar

Hi Gergely,

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

Thanks,

Gaurav

SAS Employee
Posts: 340

Re: Syntax error while providing options in macro, I also tried %options since options used inside macro but no luck

Posted in reply to gauravkodmalwar

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

options mprint mlogic symbolgen mcompilenote=all;

Contributor
Posts: 28

Re: Syntax error while providing options in macro, I also tried %options since options used inside macro but no luck

Posted in reply to gergely_batho

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

Super User
Posts: 19,851

Re: Syntax error while providing options in macro, I also tried %options since options used inside macro but no luck

Posted in reply to gauravkodmalwar

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

SAS Employee
Posts: 340

Re: Syntax error while providing options in macro, I also tried %options since options used inside macro but no luck

Posted in reply to gauravkodmalwar

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.

Contributor
Posts: 28

Re: Syntax error while providing options in macro, I also tried %options since options used inside macro but no luck

Posted in reply to gergely_batho

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.

SAS Employee
Posts: 340

Re: Syntax error while providing options in macro, I also tried %options since options used inside macro but no luck

Posted in reply to gauravkodmalwar

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.

Super User
Posts: 7,832

Re: Syntax error while providing options in macro, I also tried %options since options used inside macro but no luck

Posted in reply to gauravkodmalwar

It looks like you call the macro in a data statement (not step, statement!) before the semicolon.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor
Posts: 28

Re: Syntax error while providing options in macro, I also tried %options since options used inside macro but no luck

Posted in reply to KurtBremser

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

SAS Employee
Posts: 340

Re: Syntax error while providing options in macro, I also tried %options since options used inside macro but no luck

Posted in reply to gauravkodmalwar

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ó

Contributor
Posts: 28

Re: Syntax error while providing options in macro, I also tried %options since options used inside macro but no luck

Posted in reply to gergely_batho

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.

SAS Employee
Posts: 340

Re: Syntax error while providing options in macro, I also tried %options since options used inside macro but no luck

Posted in reply to gauravkodmalwar

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);

Contributor
Posts: 28

Re: Syntax error while providing options in macro, I also tried %options since options used inside macro but no luck

Posted in reply to gergely_batho

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.

Ask a Question
Discussion stats
  • 16 replies
  • 402 views
  • 0 likes
  • 5 in conversation