Is there a way to set NOMPRINT from within a macro without having the OPTIONS statement show up in the log? The macro in question (let's call it %RESULT) will use DATA, PROC, and macro steps to derive the value of a macro variable. At the very end the macro will report the result to the log with a %PUT statement. Ideally the macro would add nothing to the log prior to the %PUT statement at the end. Is this possible?
*--- macro in concept ---;
%macro result(data=);
DATA...
PROC...
%if...
%put &=result;
%mend result;
%result(data=cars)
*--- desired log lines ---;
%result(data=cars)
RESULT=428
Note: this is a utility macro, so I will have no control over whether MPRINT is on/off when the macro is called.
@ShaneRosanbalm if you're developing macros, one solution that I don't like, is you can look at the STORED and SECURE option to suppress the code from the user.
http://www.amadeus.co.uk/sas-training/tips/5/1/63/how-to-keep-secret-code-secret.php
1. Use PROC OPTIONS to determine the value of the option MPRINT in the beginning.
2. Use Options NONOTES to suppress the notes
Quick sketch to show how that works.
Just note that the options word will show up in the macro execution so if that's not allowed not sure how you'd do it. Maybe proc options as well? I'm not even sure if you can set options from that proc 🙂
Reeza,
Thanks for the suggestion, but I don't think that works. I don't want anything in my log between the %RESULT call and the %PUT of the results. I think using PROC OPTIONS would give me the same problem as OPTIONS NOMPRINT (namely, the PROC statement would show up in the log). Similarly with OPTIONS NONOTES; if I put this in the macro, I will see OPTIONS NONOTES in my log before I see the %PUT results. My goal is to get MPRINT (and NOTES) turned off without any evidence of a statement having been executed. Perhaps I ask the impossible. Though I hope not.
Thanks for taking time to make the suggestion.
@ShaneRosanbalm Then @LaurieF solution to use the function GETOPTION will work.
As long as the requirements are what you stated, this appears to work.
I don't want anything in my log between the %RESULT call and the %PUT of the results.
%macro test;
%let op_mprint = %sysfunc(getoption(mprint));
%let op_notes = %sysfunc(getoption(notes));
options nonotes;
options nomprint;
proc sql noprint;
select max(age) into: max_age from sashelp.class;
quit;
options &op_mprint &op_notes;
%put Max Age -> &max_age;
%mend;
%test;
@LaurieFIf mprint is turned on when the %test macro is called, there are a couple of lines generated in the log prior to the %PUT.
220 %test;
MPRINT(TEST): options nonotes;
MPRINT(TEST): options nomprint;
MPRINT(TEST): ;
Max Age -> 16
@Reeza You can get the current value of course from:
%let mprint = %sysfunc(getoption(mprint));
@ShaneRosanbalm If you don't the option text to appear from the execution of the macro, set the option within autoexec. Otherwise, if mprint is already set on, turning it off within the macro will always appear.
If you want to get really geeky, though, you can redirect the log output to a work library catalogue entry, then throw it away. But you'll still get at least a hint somewhere that you've done this.
@ShaneRosanbalm if you're developing macros, one solution that I don't like, is you can look at the STORED and SECURE option to suppress the code from the user.
http://www.amadeus.co.uk/sas-training/tips/5/1/63/how-to-keep-secret-code-secret.php
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.