I oftentimes monitor MACRO iterations as follows.
%macro repeat; %do i=1 %to 100; %if %sysfunc(mod(&i.,10))=0 %then %put NOTE: &i.th iteration now; %end; %mend; %repeat;
I can do the same thing in DATA as follows.
data _null_; do i=1 to 100; if mod(i,10)=0 then put i; end; run;
I use this code as something similar to a loading bar—the code notifies at the 10th, 20th iterations, etc. I tried to do the identical thing in IML but failed because PUT in IML works differently.
proc iml; do i=1 to 100; if mod(i,10)=0 then put i; end; quit;
The log is here.
1 proc iml; NOTE: IML Ready 2 do i=1 to 100; 3 if mod(i,10)=0 then put i; 4 end; ERROR: No current file to write to. statement : PUT at line 3 column 21 5 quit; NOTE: Exiting IML. NOTE: The SAS System stopped processing this step because of errors. NOTE: PROCEDURE IML used (Total process time): real time 0.01 seconds cpu time 0.01 seconds
Second, I tried CALL SYMPUT and %PUT instead, but still failed.
proc iml; do i=1 to 100; if mod(i,10)=0 then do; call symputx("i",i); %put &i.; end; end; quit;
The corresponding log is here.
1 proc iml; NOTE: IML Ready 2 do i=1 to 100; 3 if mod(i,10)=0 then do; 4 call symputx("i",i); 5 %put &i.; 100 6 end; 7 end; 8 quit; NOTE: Exiting IML. NOTE: PROCEDURE IML used (Total process time): real time 0.01 seconds cpu time 0.01 seconds
Is there any considerable alternative in IML? Much appreciate again.
Thanks for the helpful post, but I have one additional question about that. I just tried the following.
proc iml; i=1; submit i; %put NOTE: &i; endsubmit; quit;
Sadly, the %PUT inside spits out nothing due to the colon : right after the NOTE. I want to use the NOTE: if possible as it highlights anything in a log. Do you have any suggestion in this respect?
By default, NOTEs are turned off in a SUBMIT block. Use OPTIONS NOTES at the top of the SUBMIT block, as follows:
/* write NOTE: <message> */ submit i; options notes; /* turn on notes */ %put NOTE: Iteration = &i; /* displays NOTE: in color */ endsubmit;
Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.
Find more tutorials on the SAS Users YouTube channel.