How to set NOMPRINT without seeing corresponding OPTIONS statement in log?

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 16
Accepted Solution

How to set NOMPRINT without seeing corresponding OPTIONS statement in log?

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.


Accepted Solutions
Solution
‎02-27-2017 10:21 AM
Super User
Posts: 17,819

Re: How to set NOMPRINT without seeing corresponding OPTIONS statement in log?

@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

 

 

View solution in original post


All Replies
Super User
Posts: 17,819

Re: How to set NOMPRINT without seeing corresponding OPTIONS statement in log?

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 Smiley Happy

Occasional Contributor
Posts: 16

Re: How to set NOMPRINT without seeing corresponding OPTIONS statement in log?

[ Edited ]

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.

Super User
Posts: 17,819

Re: How to set NOMPRINT without seeing corresponding OPTIONS statement in log?

@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;

 

 

 

Super Contributor
Posts: 251

Re: How to set NOMPRINT without seeing corresponding OPTIONS statement in log?

That's exactly the technique I use in my toolkit macros. I often do the reverse as well: a debug option for setting all the mlogicing and symbolgening on, then turning them off at the end.
Occasional Contributor
Posts: 16

Re: How to set NOMPRINT without seeing corresponding OPTIONS statement in log?

@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

 

 

Super Contributor
Posts: 251

Re: How to set NOMPRINT without seeing corresponding OPTIONS statement in log?

@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.

Solution
‎02-27-2017 10:21 AM
Super User
Posts: 17,819

Re: How to set NOMPRINT without seeing corresponding OPTIONS statement in log?

@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

 

 

Occasional Contributor
Posts: 16

Re: How to set NOMPRINT without seeing corresponding OPTIONS statement in log?

Using STORE and SECURE appears to be the only way to keep the log 100% clear of any output between the macro call (%test) and the desired result (%put). Thanks to @Reeza  and @LaurieF  for their suggestions.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 8 replies
  • 231 views
  • 1 like
  • 3 in conversation