BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ShaneRosanbalm
Obsidian | Level 7

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

@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

8 REPLIES 8
Reeza
Super User

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 🙂

ShaneRosanbalm
Obsidian | Level 7

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.

Reeza
Super User

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

 

 

 

LaurieF
Barite | Level 11
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.
ShaneRosanbalm
Obsidian | Level 7

@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

 

 

LaurieF
Barite | Level 11

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

Reeza
Super User

@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

 

 

ShaneRosanbalm
Obsidian | Level 7

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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