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;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 1079 views
  • 3 likes
  • 3 in conversation