The code below must do the same thing in three different ways using the DATA step, SAS/IML, and SAS Macro, respectively, but unfortunately the third one doesn't work and just produces some warning messages saying "WARNING: Argument 2 to function PUTN referenced by the %SYSFUNC or %QSYSFUNC macro function is out of range."
data _null_;
do I=1 to 10;
J=putn(I,"z4.");
put J;
end;
run;
proc iml;
file log;
do I=1 to 10;
J=putn(I,"z4.");
put J;
end;
closefile log;
quit;
%macro REPEAT;
%do I=1 %to 10;
%let J=%sysfunc(putn(&I.,"z4."));
%put &J.;
%end;
%mend;
%REPEAT;
I just realized that, unlike the rest cases, I should drop the double quotation marks around z4. in the PUTN, but I can't understand why the quotation marks, which are necessary for the rest cases, must be suppressed here. Why do they have different grammatical rules?
No quotes in the z4 in the last one.
In macro language all quotes are dropped in literals. I think it’s because of how the macro processor works and it parses it all as text unless specified otherwise.
https://stats.idre.ucla.edu/wp-content/uploads/2016/02/bt185.pdf
More generally, it’s a rule In macro language, docs:
@Junyong wrote:
The code below must do the same thing in three different ways using the DATA step, SAS/IML, and SAS Macro, respectively, but unfortunately the third one doesn't work and just produces some warning messages saying "WARNING: Argument 2 to function PUTN referenced by the %SYSFUNC or %QSYSFUNC macro function is out of range."
data _null_; do I=1 to 10; J=putn(I,"z4."); put J; end; run; proc iml; file log; do I=1 to 10; J=putn(I,"z4."); put J; end; closefile log; quit; %macro REPEAT; %do I=1 %to 10; %let J=%sysfunc(putn(&I.,"z4.")); %put &J.; %end; %mend; %REPEAT;
I just realized that, unlike the rest cases, I should drop the double quotation marks around z4. in the PUTN, but I can't understand why the quotation marks, which are necessary for the rest cases, must be suppressed here. Why do they have different grammatical rules?
No quotes in the z4 in the last one.
In macro language all quotes are dropped in literals. I think it’s because of how the macro processor works and it parses it all as text unless specified otherwise.
https://stats.idre.ucla.edu/wp-content/uploads/2016/02/bt185.pdf
More generally, it’s a rule In macro language, docs:
@Junyong wrote:
The code below must do the same thing in three different ways using the DATA step, SAS/IML, and SAS Macro, respectively, but unfortunately the third one doesn't work and just produces some warning messages saying "WARNING: Argument 2 to function PUTN referenced by the %SYSFUNC or %QSYSFUNC macro function is out of range."
data _null_; do I=1 to 10; J=putn(I,"z4."); put J; end; run; proc iml; file log; do I=1 to 10; J=putn(I,"z4."); put J; end; closefile log; quit; %macro REPEAT; %do I=1 %to 10; %let J=%sysfunc(putn(&I.,"z4.")); %put &J.; %end; %mend; %REPEAT;
I just realized that, unlike the rest cases, I should drop the double quotation marks around z4. in the PUTN, but I can't understand why the quotation marks, which are necessary for the rest cases, must be suppressed here. Why do they have different grammatical rules?
the answer to your question is best understood by reviewing how tokenisation of literal tokens and special tokens work at compile time and what tokens are sent to compiler for datastep execution
Doesn't take too long to grasp as that's mostly common to many programming languages. hth
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.