BookmarkSubscribeRSS Feed
munitech4u
Quartz | Level 8

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.

10 REPLIES 10
art297
Opal | Level 21

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.

munitech4u
Quartz | Level 8

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.

hdodson_pacificmetrics_com
Calcite | Level 5


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

art297
Opal | Level 21

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;

munitech4u
Quartz | Level 8

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.

Astounding
PROC Star

Remove the semicolon after "then"

munitech4u
Quartz | Level 8

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

hdodson_pacificmetrics_com
Calcite | Level 5

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)

munitech4u
Quartz | Level 8

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

hdodson_pacificmetrics_com
Calcite | Level 5

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?

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 10 replies
  • 1114 views
  • 0 likes
  • 4 in conversation