BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Junyong
Pyrite | Level 9

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.

1 ACCEPTED SOLUTION
3 REPLIES 3
Junyong
Pyrite | Level 9

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?

Rick_SAS
SAS Super FREQ

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;

sas-innovate-2024.png

 

Time is running out to save with the early bird rate. Register by Friday, March 1 for just $695 - $100 off the standard rate.

 

Check out the agenda and get ready for a jam-packed event featuring workshops, super demos, breakout sessions, roundtables, inspiring keynotes and incredible networking events. 

 

Register now!

Multiple Linear Regression in SAS

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.

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 3 replies
  • 913 views
  • 3 likes
  • 3 in conversation