DATA Step, Macro, Functions and more

Write macro using data _null_ and put statement

Reply
Occasional Contributor
Posts: 14

Write macro using data _null_ and put statement

I am using SAS9.2 on windows, when I submit the following statements:
*****************************************************;
%let mymacro=%str(C:\mymacro.sas);
data _null_;
file mymacro;
put "%macro mymacro(crt=);" ;
put "More code";

put "%mend mymacro();" ;
run;
****************;

I got this note in the log and the data step doesn't finish:
***Log ***;
101 data _null_;
102 file mymacro;
103 put "%macro mymacro(crt=);"
---------
49
103! ;
NOTE 49-169: The meaning of an identifier after a quoted string may change in a future SAS release. Inserting white space
between a quoted string and the succeeding identifier is recommended.

104 put "More code";
105
106 put "%mend mymacro();" ;
107 run;
**********end of log*********;

If I submit the following code:
***************************;
data _null_;
file mymacro;
put "%%macro mymacro(crt=);" ;
put "More code";

put "%%mend mymacro();" ;
run;
***********;

I got the following output, noticing the double %. How do I make SAS to output only one %?

*******************;
%%macro mymacro(crt=);
More code
%%mend mymacro();
*****************************;
Super Contributor
Super Contributor
Posts: 3,174

Re: Write macro using data _null_ and put statement

Suggest you share the first 100 lines of your SAS log as well.....

Scott Barry
SBBWorks, Inc.
Occasional Contributor
Posts: 14

Re: Write macro using data _null_ and put statement

That is all there is. I also got the 'Data Step running' in the Editor window bar, i.e., it hangs there until I quit SAS. Then it is saying %mend missing in the log before exiting. Essentially, I wonder how I can write a macro with put statement?

*************************************************************;
1 %let mymacro=%str(C:\mymacro.sas);
2 data _null_;
3 file mymacro;
4 put "%macro mymacro(crt=);"
--------
49
4 ! ;
NOTE 49-169: The meaning of an identifier after a quoted string may change in a future SAS release. Inserting white space
between a quoted string and the succeeding identifier is recommended.

5 put "More code";
6
7 put "%mend mymacro();" ;
8 run;
Occasional Contributor
Posts: 14

Re: Write macro using data _null_ and put statement

It dawned on me that if I used single quote, I don't get the note in the log and the output is fine with one %!

Thanks to everyone who tried to help!

*****************************************************;
%let mymacro=%str(C:\mymacro.sas);
data _null_;
file mymacro;
put '%macro mymacro(crt=);' ;
put "More code";

put '%mend mymacro();' ;
run;
****************;
Ask a Question
Discussion stats
  • 3 replies
  • 152 views
  • 0 likes
  • 2 in conversation