This custom step redirects log & procedural output of downstream SAS programs to specified external files, also reassigning them to the default location when needed.
This will prove useful for scenarios requiring automated generation of log or output files. For example, this step can be used to fulfill governance, regulatory and compliance objectives in industries such as banking and life sciences.
Click on the picture below to watch a quick demo:
- Requirements
- Parameters
- Some common gotchas
- Run-time Control
- Documentation
- SAS Program
- Installation and Usage
- Created/Contact
- Change Log
- A SAS Viya 4 environment version 2024.04 or later.
-
Redirection operation (drop-down list, required): choose whether to redirect only the log, only the output, both log and output, or to reassign to default location.
-
Log file location (file selector, enabled if log redirection is selected): provide a path to a log file on the file system. The path should be writeable.
-
Output file location (file selector, enabled if output redirection is selected): provide a path on the file system. The path should be writeable.
- Reference dataset (output port, required): connect a SAS dataset or CAS table to the output port of this custom step, to hold references to the redirected files. A timestamp is also added to indicate when this redirection occurred.
Every run of this step appends information to the reference dataset. The dataset is created if it does not exist the first time.
When used with improper understanding or familiarity, proc printto (the driving functionality in this custom step) might lead to confusion or errors. Please be aware of the following:
-
Log / output redirection are not perfect substitutes for ODS HTML / Excel etc. The purpose behind redirection is for creating separate, specified log or listing files for persistence or communication. ODS HTML (or ODS EXCEL and other equivalents) perform a similar function but offer more functionality such as formatting etc.
-
Output redirection does not automatically extend to plots, i.e. charts. You'll find upon examination that the log may provide an entry stating where the plot has been saved. Use the ODS listing command to redirect graphics. See https://communities.sas.com/t5/Graphics-Programming/Specify-SGPlot-png-output-location/td-p/622251 for a discussion.
-
When used within a SAS Studio Flow, log redirection will affect the status of nodes in a flow. You will find that even when nodes are run successfully, a redirected log may cause the green tick mark to not appear. Please be aware of the same.
-
This is NOT meant to be a log / output suppression mechanism for SAS Studio Flows. This step neither guarantees nor intends to change the behaviour of product features and configuration in SAS Studio Flows or Steps.
Note: Run-time control is optional. You may choose whether to execute the main code of this step or not, based on upstream conditions set by earlier SAS programs. This includes nodes run prior to this custom step earlier in a SAS Studio Flow, or a previous program in the same session.
Refer this blog (https://communities.sas.com/t5/SAS-Communities-Library/Switch-on-switch-off-run-time-control-of-SAS-Studio-Custom-Steps/ta-p/885526) for more details on the concept.
The following macro variable,
_rl_run_trigger
will initialize with a value of 1 by default, indicating an "enabled" status and allowing the custom step to run.
If you wish to control execution of this custom step, include code in an upstream SAS program to set this variable to 0. This "disables" execution of the custom step.
To "disable" this step, run the following code upstream:
%global _rl_run_trigger;
%let _rl_run_trigger =0;
To "enable" this step again, run the following (it's assumed that this has already been set as a global variable):
%let _rl_run_trigger =1;
IMPORTANT: Be aware that disabling this step means that none of its main execution code will run, and any downstream code which was dependent on this code may fail. Change this setting only if it aligns with the objective of your SAS Studio program.
-
Documentation for the Proc Printto statement which redirects log and procedure output.
-
This custom step makes use of a GOTO statement, a practice that purists consider 'bad' programming. At the same time, GOTO can be tolerated in certain situations, as discussed in this blog (and hopefully valid in this context). Note that there are many disussions on GOTO online, and this blog is presented as just one example.
-
For a discussion on alternatives for graphs and charts, see this.
Refer here for the SAS program used by the step. You'd find this useful for situations where you wish to execute this step through non-SAS Studio Custom Step interfaces such as the SAS Extension for Visual Studio Code, with minor modifications.
- Refer to the steps listed here.
- Lou Galway (lou.galway@sas.com)
- Sundaresh Sankaran (sundaresh.sankaran@sas.com)
- Version 1.0 (25MAY2024)
- Initial version