BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Ksharp
Super User

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;
ThaoLinh
Calcite | Level 5

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;
ChrisNZ
Tourmaline | Level 20

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;

 

Ksharp
Super User

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;
ChrisNZ
Tourmaline | Level 20

@Ksharp I've never seen this syntax to redirect to a null file. Are you sure it's correct?

Patrick
Opal | Level 21

@ThaoLinh @Ksharp 

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_0-1634003401303.png

 

Ksharp
Super User

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
Super User

"filename x temp;" create a temp file named X .

"proc printto log=x new;run;" redirect LOG into the temp file X .

But I think you should give this credit to @Quentin . who is genius to take this idea.
Patrick
Opal | Level 21

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

Ksharp
Super User

@Patrick  did you see my LOG ? 

I think it is depend on OS and version of SAS .

Patrick
Opal | Level 21

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

Patrick
Opal | Level 21

@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

 

Ksharp
Super User
It is magic. I think you should start a brand-new sas session. I notice your code number is not start from 1 ?

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 42 replies
  • 3092 views
  • 32 likes
  • 10 in conversation