Macro is throwing syntax error

Reply
Regular Contributor
Posts: 190

Macro is throwing syntax error

Hi,

I am trying to execute one simple macro in program:

Program calls macro library:

%include fmt;

if _n_ eq 1 then

%wrthdr;

fmt contains the macro:

%macro wrthdr;

put

"xxx";

%mend;

But its throwing me error:

1519  +%MACRO WRTHDR;                                           
1520  + PUT                                                     
1520  + PUT                                                     
        ___                                                     
        180                                                     

ERROR 180-322: STATEMENT IS NOT VALID OR IT IS USED OUT OF PROPER ORDER. 

Any ideas please? I am using SAS on Mainframes and fmt is the DD name which contains the library information for macro.

PROC Star
Posts: 7,491

Re: Macro is throwing syntax error

Posted in reply to munitech4u

The macro isn't throwing a syntax error, SAS is!  The following works:

%include "c:\art\fmt";

data want;

  set sashelp.class;

  if _n_ eq 1 then %wrthdr;

run;

However, your macro won't appear to have done anything.  If you wanted xxx to appear in the log, your macro should have used %put rather than put.

Regular Contributor
Posts: 190

Re: Macro is throwing syntax error

That syntax works for windows. In windows I have tested it works fine. But in mainframes it tries to call the macro from different position by using %include DDname,

where DDname contains the macro. When it tries to compile and go through the include statement and reached macro. It throws the error mentioned above.

Also the purpose of macro is to print multiple headers and then corresponding variable values. It will be called in different programs.

Contributor
Posts: 22

Re: Macro is throwing syntax error

Posted in reply to munitech4u


Hello there,

     I can't find an error when I run this code:

  %macro wrthdr;

    put "xxx";

  %mend;

  data _null_;

    if _n_=1 then %wrthdr;

  run;

     Is there a little more context that could be helpful? Does the code run fine with the macro call in question commented out?

Thanks,

Huey

PROC Star
Posts: 7,491

Re: Macro is throwing syntax error

Posted in reply to munitech4u

Did you try to run the code I sent in my last post?

I think you are trying use an if statement without wrapping it in a datastep.  The following would produce the same error, on a windows system, that you are getting:

%include "c:\art\fmt";

if _n_ eq 1 then %wrthdr;

Regular Contributor
Posts: 190

Re: Macro is throwing syntax error

I am calling it within data step only:

data _null_;

set datasetname;

if _n_ eq 1 then;

%wrthdr;

Also to add, I just tested the piece of code works fine, when macro is coded within program, but since we are defining it externally, we have to include it using %include only if I am correct. But while doing %include it throws error as I mentioned in my very first post.

Super User
Posts: 5,516

Re: Macro is throwing syntax error

Posted in reply to munitech4u

Remove the semicolon after "then"

Regular Contributor
Posts: 190

Re: Macro is throwing syntax error

Posted in reply to Astounding

I mistakenly put that here, I am running without semicolon.

Contributor
Posts: 22

Re: Macro is throwing syntax error

Posted in reply to munitech4u

Just to be clear, you're saying that simply submitting the %INCLUDE fmt; throws the error?

If so, it's as if the code within the macro is being executed (rather than the macro just being compiled) when you %INCLUDE it. And I'm not sure why that would happen.

If you're actually trying to use a Stored Macro Library then use the following code instead of %INCLUDE:

       libname fmt 'where-fmt-lives';

          options mstored sasmstore=fmt;

     (SAS(R) 9.2 Macro Language: Reference)

Regular Contributor
Posts: 190

Re: Macro is throwing syntax error

Posted in reply to hdodson_pacificmetrics_com

I tried libname option, its not able to recognize 'directory' name, as its not a windows operating system, and in mainframes stores in PDS: AAA.BBB.CCC

Contributor
Posts: 22

Re: Macro is throwing syntax error

Posted in reply to munitech4u

munitech4u wrote:

I tried libname option, its not able to recognize 'directory' name, as its not a windows operating system, and in mainframes stores in PDS: AAA.BBB.CCC

If the filename statement worked to establish the fileref fmt, so too should a libname statement using similar syntax, wouldn't you think?

Would you mind posting your filename statement for fmt?

Ask a Question
Discussion stats
  • 10 replies
  • 421 views
  • 0 likes
  • 4 in conversation