I have the following macro:
%MACRO Loop_1;
%DO i = 1 %TO 500 ;
%Macro_first(&i);
%END;
%MEND Loop_1;
The problem is that after a certain amount of loops, the log window becomes full and needs to be cleared before the code progresses.
I googled this, and found:
dm 'log;clear;';
But I can't seem to implement it.
If I put it outside the loop, it doesn't work (obviously).
If I put it in inside the loop, the "dm" stays black, so it seems that it's not registering properly as a SAS statement, and when I use
%dm, it's being read as a macro.
Any help is appreciated!
Don't do a clear. Use PROC PRINTTO to write the log to a file. If there is an error somewhere, then you can view the log in the file. If you do a clear, errors are gone.
If your log is that big and it takes a considerable time to run then consider running your program as a batch SAS job then your log can grow as big as necessary.
@UniversitySas wrote:
I have the following macro:
I googled this, and found:
dm 'log;clear;';
But I can't seem to implement it.
If I put it outside the loop, it doesn't work (obviously).
If I put it in inside the loop, the "dm" stays black, so it seems that it's not registering properly as a SAS statement, and when I use
%dm, it's being read as a macro.
Any help is appreciated!
The "DM" in " dm 'log; clear'; " refers to Display Manager, the SAS interface that is sometimes referred to as Base or Foundation SAS. So if you are working in SAS Studio, Enterprise Guide or Viya I would not expect that to work.
You can route the log to a file with Proc Printto (or to "nowhere" by using the file name dummy) before you enter the loop. Remember to route it back to the log window after the loop:
* Disable logging;
filename mylog dummy;
proc printto log=mylog;
run;
* Useless macro generating long log;
%macro m;
%do i = 1 %to 100;
data test;
a = 1;
run;
%end;
%mend;
%m;
* Enable logging;
proc printto;
run;
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.