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.
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.
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.
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
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;
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.
Remove the semicolon after "then"
I mistakenly put that here, I am running without semicolon.
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;
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
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 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.