BookmarkSubscribeRSS Feed

Viya 2020.1.5 (April 2021) – Introducing Custom Steps in SAS Studio Flow

Started ‎05-28-2021 by
Modified ‎05-28-2021 by
Views 5,430

New in the Viya 2020.1.5 (April 2021) stable release of SAS Studio Flow is the Custom Step framework.  Custom Steps enable you to create a user interface to complete a specific task.  They can then be used in multiple SAS Studio Flows to ensure a common, repeatable process.  Custom Steps are saved in SAS Content; therefore, they can be shared with others at your site.  Since Custom Steps are SAS Content, they can also be exported by an Administrator in SAS Environment Manager as a JSON file and shared with other sites.  Note: Custom Step functionality requires a SAS Studio Analyst license.  

 

For this introduction to Custom Steps in SAS Studio Flow, I will review how I created and used a custom step to anonymize and mask data using standardization definitions from the SAS Quality Knowledge Base (QKB).  For more information on these definitions, you can view this YouTube video.

 

Creating a Custom Step

Custom Steps are created on the Steps pane of SAS Studio. 

 

Select  CustomStep_icon1.pngCustom step quick start to create a new custom step.

 

 

mk_2_CustomStep_1.png

Select any image to see a larger version.
Mobile users: To view the images, select the "Full" version at the bottom of the page.

 

 

This opens the Custom Step screen for you to write your Prompt UI and Template code.  The first thing to do is to save your custom step with a name that lets others know what it does.  The custom step is saved in the SAS Content folder you specify.  I save mine as Anonymize and Mask Data.

 

CustomStep_2.png

 

I suggest that you review the Starter templates and Sample controls before creating your custom step.  They help you understand the syntax of the JSON for the Prompt UI section and how to reference the macro variables for the selections in your SAS code in the Template section.

 

CustomStep_3.png

 

Prompt UI

The Prompt UI section is written in JSON.  The Starter templates and Sample controls give you some good examples of the syntax to use.  

 

The Prompt UI consists of pages.  At least one page must be present which is why when you start creating a custom step the syntax for page1 is provide.  You should change the id and label to something appropriate for your custom step.  I change the id to maskData and the label to Anonymize and Mask Data and save my changes.

 

CustomStep_4.png

 

I only need to have one page for my task, but if needed, you could add additional pages adhering to the JSON syntax for the type page.  

 

The next step is start adding children information to the page.  I add an inputtable and outputtabletype.  This creates an input and output port for your custom step in the SAS Studio Flow.  The JSON looks like this:

 

CustomStep_5.png

 

I select Preview to review what the Prompt UI looks like:

 

CustomStep_6.png

 

 

Next, add any other user prompts you need to run your task.  I need to add prompts to select which field from the input table to standardize and which data masking definition to use from the QKB.  To select the column to standardize I use the type columnselector and specify that only 1 column can be selected.  For the data masking definition selection, I use the type dropdown and specify the valid selections in the items section.

 

CustomStep_7.png

 

 

I select Preview to review what the Prompt UI looks like now:

 

CustomStep_8.png

 

 

If you want to specify default values for any of the prompts, you do that in the values section.  

 

Here is the full JSON for the Prompt UI:

 

{
   "syntaxversion": "1.0.0",
   "pages": [
   {
	"id": "maskData",
	"type": "page",
	"label": "Anonymize and Mask Data",
	"children": [
	{
		"id": "inTable",
		"type": "inputtable",
		"label": "Select an input table:",
		"required": true
	},
	{
		"id": "inColumn",
		"type": "columnselector",
		"label": "Select a column to mask:",
		"table": "inTable",
		"order": false,
		"max": 1,
		"min": 1
	},
		{
		"id": "selectedDefinition",
		"type": "dropdown",
		"label": "Select data masking definition:",
		"items": [
			{
			   "value": "Anonymize E-mail Domain"
			},
			{
			   "value": "Mask All Characters"
			},
			{
			   "value": "Mask All Characters Except First and Last"
			},
			{
			   "value": "Mask Digits"
			},
			{
			   "value": "Mask E-mail Domain"
			},
			{
			   "value": "Mask E-mail Mailbox"
			},
			{
			   "value": "Mask E-mail Mailbox Except First and Last"
			},
			{
			   "value": "Mask E-mail Sub-Domain"
			},
			{
			   "value": "Mask Letters"
			},
			{
			   "value": "Mask Partial String"
			}
			],
			   "required": true,
			   "placeholder": "(Data masking definitions)"
		},
	       {
		"id": "outTable",
		"type": "outputtable",
		"label": "Specify the output table:",
		"required": true
		}
	]
   }
   ],
   "values": {}
}

 

Template Code

The Template section is where you write the SAS code for the task to be performed by the custom step.  The Starter templates and Sample controls give you some good examples of the syntax to use.  

 

I add my code to perform my task of applying a data masking standardization definition from the QKB.  In the code I use macro variables based on the id of the item from my Prompt UI.  Note the special syntax used for the type columnselector (&inColumn_1_name) – inColumn is my columnselector id and 1 refers to the first selected value and name refers to the column name selected.

 

CustomStep_9.png

 

Note:  The QKB locale referenced doesn't matter since all the standardization definitions referenced in this task are Global-level definitions. However, you could easily add a prompt to select the desired QKB-locale and then use that selected value in the code.  

 

Here is the full code for the Template:

 

/* Load ENUSA QKB Locale */
%DQLOAD(DQLOCALE=(ENUSA));

/* Apply Data Masking Standardization Definition */
data &outTable;
   set &inTable;
   maskedColumn=dqStandardize(&inColumn_1_name,"&selectedDefinition", "ENUSA");
run ;

 

Using a Custom Step in a SAS Studio Flow

Once the Custom Step has been saved, it is available for selection under the Custom Steps section in the Steps pane. You can now create a SAS Studio Flow using the custom step.

 

I create a new SAS Studio Flow and add the Table step to read in the BASEBALL table from the SASHELP library.

 

 

CustomStep_10.png

 

Next, I add the Custom Step I created called Anonymize and Mask Data to the flow and connect it to the BASEBALL table.

 

CustomStep_11.png

 

Note: The Input and Output table selections aren't displayed on the page since they are translated into ports for the node. Now, I make my desired selections for the node.

 

CustomStep_12.png

 

I then run my flow and view the results in the output port of the custom step.

 

CustomStep_13.png

 

I can use the same custom step in another flow.  Here I am reading in data from a Postgres table and using the Anonymize E-mail Domain standardization definition on the email field from the table.

 

CustomStep_14.png

 

 

When I run the flow and preview the results this is what I get:

 

CustomStep_15.png

 

Summary

This Custom Step framework gives you the ability to create your own repeatable tasks for use in SAS Studio Flows.  Review the Starter templates and Sample Controls for syntax help.  Hope you enjoy making your own custom steps!  

 

If you want to try the example custom step I made, you can copy the Prompt UI JSON and Template code from above. Note:  You will need access to the SAS Viya 2020.1.5 (April 2021) or later stable release with a SAS Studio Analyst license and the SAS QKB CI 32 or later release installed.  

 

Over the coming months this Custom Step framework will be expanded.  Stay tuned to find out more!  

 

References

 

Find more articles from SAS Global Enablement and Learning here.

Version history
Last update:
‎05-28-2021 12:43 PM
Updated by:
Contributors

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!

Free course: Data Literacy Essentials

Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning  and boost your career prospects.

Get Started

Article Tags