This custom step generates a new column containing a unique identifier (ID) per observation for a given input CAS table.
Since Cloud Analytics Services (CAS) processes across multiple threads, the conventional method of using the _N_ automatic variable (as used in SAS Compute) does not ensure uniqueness.
There exists both a workaround (concatenating the thread id with the _N_ variable) and a CAS action (included in all Viya offerings) to create a unique ID column. This custom step makes use of the CAS action (textmanagement.generateIds) to generate a unique ID.
Here's a general idea of how this custom step works (the below is an animated GIF)
Tested in Viya 4, Stable 2022.11
-
A SAS Viya 4 environment (monthly release 2022.11 or later) with SAS Studio Flows.
-
At runtime: an active connection to CAS: This custom step requires Cloud Analytics Services. Ensure you have an active CAS connection available prior to running the same.
- Input port: connect an input CAS table to the input port.
- Name desired for the unique ID column.
- Output port: connect an output table (which needs to be a CAS table) to the output port.
Note that all columns are copied over to the output table.
Note that this is optional.
In some scenarios, you may wish to dynamically control whether this custom step runs or simply "passes through" without doing anything, in a SAS Studio session. The following macro variable is set to initialize with a value of 1 by default, indicating an "enabled" status and allowing the custom step to run.
Refer this blog for more details on the concept.
/* To demonstrate the default value of the trigger macro variable */;
&_gui_run_trigger.=1;
If you wish to control execution of this custom step programmatically (within a session, including execution of a SAS Studio Flow), make sure that an upstream SAS program sets the macro variable to 0. Setting the value to 0 "disables" the execution of this custom step.
For example, to "disable" this step, run the following code upstream:
%global _gui_run_trigger;
%let _gui_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 _gui_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.
- The textmanagement.generateIds CAS action.
- This SAS Communities article provides the workaround mentioned earlier.
- This SAS Communities article mentioned earlier, suggests an approach through which execution of this custom step is controlled during run time.
- Refer to the steps listed here.
Version: 1.2 (15AUG2023) - Added trigger variable to control run-time execution, plus stylistic changes.
Version: 1.1. (07FEB2023) - Feedback incorporation
Version: 1.0. (02FEB2023) - Unpublished on GitHub; copyVars option