Great Idea. Use PROC PRINTTO to suppress print code.
%macro secure(val)/secure; filename x DUMMY; proc printto log=x new;run; data T; X="&val"; putlog "This data step was generated from a secure macro with value &val.."; run; proc print data=sashelp.class;run; proc printto;run; %mend secure; options MPRINT MLOGIC SYMBOLGEN SOURCE SOURCE2; data _null_; call execute('%secure(Q)'); run;
I think Ksharp's answer is correct, highly effective, and simple.
One more question, could you please explain to me how this part works?
filename x temp;
proc printto log=x new;run;
The temp device points to a temporary file that disappears with the SAS session.
This file is deleted when the SAS session ends cleanly or when the fileref is changed/cleared.
Cunning users could find it in the WORK library with a name starting with #LN while the program is running, or if the SAS session fails.
You should direct the log to the null device rather than to a temp file in my opinion.
filename X 'nul' ; * DOS syntax;
filename X '/dev/null'; * Unix syntax;
Chris,
You are right, Maybe could try this ?
%macro secure(val)/secure; proc printto log=_null_ new;run; data T; X="&val"; putlog "This data step was generated from a secure macro with value &val.."; run; proc print data=sashelp.class;run; proc printto;run; %mend secure; options MPRINT MLOGIC SYMBOLGEN SOURCE SOURCE2; data _null_; call execute('%secure(Q)'); run;
@Ksharp I've never seen this syntax to redirect to a null file. Are you sure it's correct?
Not sure in which environment you are testing but in mine the timing challenge still exists. The generated SAS code gets fully printed to the SAS log. It's only when this code executes that any Proc Printto or Options will take effect and though too late to suppress printing to the SAS log.
Patrick,
I used PC version SAS under WINDOWS11 .
Maybe it is depend the OS and version of SAS.
Here is my LOG.
1 %macro secure(val)/secure; 2 proc printto log=_null_ new;run; 3 4 5 data T; 6 X="&val"; 7 putlog "This data step was generated from a secure macro with value &val.."; 8 run; 9 proc print data=sashelp.class;run; 10 11 12 proc printto;run; 13 %mend secure; 14 15 options MPRINT MLOGIC SYMBOLGEN SOURCE SOURCE2; 16 data _null_; 17 call execute('%secure(Q)'); 18 run; NOTE: DATA statement used (Total process time): real time 0.24 seconds cpu time 0.11 seconds NOTE: CALL EXECUTE generated line. 1 + proc printto log=_null_ new;run; NOTE: PROCEDURE PRINTTO used (Total process time): real time 0.00 seconds cpu time 0.00 seconds
@Ksharp But it doesn't work with call execute() as it comes too late. Else option nosource would do the job as well.
See the sample code and log I've posted and prove me wrong.
@Patrick did you see my LOG ?
I think it is depend on OS and version of SAS .
@Ksharp I did and it actually confuses the hell out of me that the OS or even version of SAS should change the logical sequence of how code gets executed.
28 %put &=SYSVLONG; SYSVLONG=9.04.01M7P080520 29 %put &=SYSSCPL; SYSSCPL=X64_10PRO
But... the log I've shared clearly falsifies the "theory" that proc printto (or optin nosource) is a 100% way for hiding the generated code.
@Ksharp I'd really be interested to understand why in my environment things are different as compared to yours.
...actually: here proc printto executes where it's favorable. Investigating further...
0 %put &=SYSVLONG; SYSVLONG=9.04.01M7P080520 31 %put &=SYSSCPL; SYMBOLGEN: Macro variable SYSSCPL resolves to X64_10PRO SYSSCPL=X64_10PRO 32 %macro secure(val)/secure; 33 proc printto log=_null_ new; 34 run; 35 data T; 36 X="&val"; 37 putlog "This data step was generated from a secure macro with value &val.."; 38 run; 39 proc print data=sashelp.class; 40 run; 41 proc printto; 42 run; 43 %mend secure; 44 45 options MPRINT MLOGIC SYMBOLGEN SOURCE SOURCE2; 46 data _null_; 47 call execute('%secure(Q)'); 48 run; NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds NOTE: CALL EXECUTE generated line. 1 + proc printto log=_null_ new; run; NOTE: PROCEDURE PRINTTO used (Total process time): real time 0.00 seconds cpu time 0.00 seconds
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.