The script neither reads nor creates conventional SAS datasets. It interacts directly with the SAS log to extract text and write it to an external text-format file.
1 Code Block
MACRO DEFINITION
Explanation : This block defines the `%cliplog` macro. It is designed to capture a section of the SAS log using Display Manager (`dm`) commands. The macro temporarily disables the `mprint` option to prevent its own instructions from being included in the captured log. It locates a string (`marker1` concatenated with `marker2`), marks this position, then marks the end of the log. The content between these two points is copied to the SAS clipboard, then written to the file specified by the `file` parameter. Finally, the `x "notepad &file"` command is used to open the generated file in Notepad, and the `mprint` option is restored.
Copied!
%macro cliplog(marker1,marker2,pos=last,file=c:\test.txt) ;
* note: split search text in half so we dont go and find it in our macro call ;
* note: save mprint option since we want mprint turned off for the macro run, otherwise
we get our search text written to the log and we will find it ;
%let o=%sysfunc(getoption(mprint)) ;
options nomprint ;
/* log;
find '&marker1&marker2' &pos;
rfind;
mark;
bottom;
mark;
store;
unmark;
notepad;
clear;
paste;
file '&file';
end
*/
dm "log;find '&marker1&marker2' &pos;mark;bottom;mark;store;unmark;notepad;clear;paste;file '&file';end" ;
* view the file in windows notepad ;
x "notepad &file" ;
options &o ;
%mend cliplog ;
Explanation : This block illustrates the use of the `%cliplog` macro. The line `***BEGIN***;` is a SAS instruction that writes a marker to the log. The comment `/* now run all the SAS code you would like to capture */` indicates where to insert the code whose log content is to be captured. The call `%cliplog(***BEGIN,***);` executes the macro to capture the log. The macro will search for the first occurrence of `***BEGIN***` (searching backward if `pos=last`), mark this position, then the end of the log, and copy the text between these two points.
Copied!
***BEGIN***; /* this marks where to start the copying from the log */
/* now run all the SAS code you would like to capture */
%cliplog(***BEGIN,***) ; /* finally we call the macro which captures the log from the point we previously marked */
1
***BEGIN***;
2
/* this marks where to start the copying from the log */
3
/* now
4
run all the SAS code you would like to capture */
5
%cliplog(***BEGIN,***) ;
6
/* finally we call the macro which captures the log from the point we previously marked */
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.