BookmarkSubscribeRSS Feed

Taking the Next Step in SAS Studio Customization - Part 1

Started ‎11-14-2023 by
Modified ‎11-14-2023 by
Views 391

 

Within SAS Studio, many users have already taken advantage of the ability to customize SAS Studio tasks to provide a starter for themselves and their coworkers. The time taken to build such custom tasks has allowed others to get started using analytical procedures within SAS without having to know all the details about coding. SAS Studio now has another means of customization available, Custom Steps. In this first, of a multipart blog, we will begin the process of creating our own SAS Studio Custom Step that then can be shared with others.

 

STEP 1: Getting Started

 

So, you have decided to create your own Custom Step within SAS Studio. What should you do first? Find a block of code, Data Step or PROC, that is utilized very often by you and your colleagues. This block of code should have many aspects that are commonly used by you and your colleagues but also have some unique additional options that could be taken advantage of when the problem dictates such. Starting with actual working code is much easier than from an open-ended scenario based structure. With the code there, we can focus our attention on the specifics of the Custom Step. In our example, we will select a block of code that performs k-means clustering. This code uses PROC KCLUS. PROC KCLUS is performing k-means, k-modes, or k-prototypes clustering on the observations using the provided input variables. This clustering is based on distances that are computed from quantitative or qualitative variables (or both).

 

proc kclus data=work.cars distance=Euclidean distancenom=binary impute=mean imputenom=mode noc=abc(minclusters=2) maxclusters=10;
input MPG_City MPG_Highway Horsepower / level=interval;
input Type Origin / level=nominal;
score out=work.clustered copyvars=(_all_);
run;

 

STEP 2: Generalizing and Expanding

 

Now that we have working code, let's decide where and how we can generalize this code to make it applicable to various situations. Begin by asking yourself, what items in the current code would change depending on the problem at hand? In our case, the following would change: name of the input dataset (work.cars), lists of variables to use (MPG_City, MPG_Highway, Horsepower for interval, Type and Origin for nominal), and the name of the output dataset (work.clustered). If you are familiar with macro variables in SAS, these would be items where we could generalize the code with macro variable replacement. This mentality is helpful here as well for generalization for Custom Steps.

 

What about expanding? These are items that are not necessary for the program to execute but are items that could be used when needed. In our code, examples of this would be the imputing of missing data (impute=mean imputenom=mode) and the maximum number of clusters that we will generate (noc=abc(minclusters=2) maxclusters=10). Yes, there are many other options and sub- options available within PROC KCLUS. Should we attempt to bring them all into our Custom Step? No, definitely not! Why shouldn't we? When creating a GUI (graphical user interface), inclusion of more options and items makes things feel cluttered and difficult to know where some options can be found. We should limit our expanding to items that are most commonly used by coworkers or yourself. Ask around. What do your coworkers use most often when they run PROC KCLUS?

 

Here is our KCLUS code with the generalizing noted within brackets { } and the expanding noted within arrows < >.

 

proc kclus data={work.cars} distance=Euclidean distancenom=binary <impute=mean imputenom=mode> <noc=abc(minclusters=2) maxclusters=10>;
input {MPG_City MPG_Highway Horsepower} / level=interval;
input {Type Origin} / level=nominal;
score out={work.clutered} copyvars=(_all_);
run;

 


STEP 3: Designing the GUI

 

We have our code ready. Now it is time to start thinking about the construction of the GUI for our Custom Step.

 

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

 

Within SAS Studio Step Designer, there are many items we can choose from to create the GUI just as we wish. Which types of items should we use with our Custom Step? The Designer has objects specific for the selection of data sets (both input and output) as well as variable selection objects. For these parts of the GUI we will simply include these as we have need of them. But what about the other options (expanding parts) of our code we included? Let's start with the option to impute missing values within our data. In this option, we will either impute or not. The answer is a simple yes or no. For this, a check box would be the best object to use. Selection of the check box would indicate we want to impute while deselection would indicate we do not.

 

What about the selection of the number of clusters to utilize? Our options here can be broken into two parts. First, we will need to decide if we want to have the number of clusters calculated using the ABC statistic or do we want to specify a specific number of clusters. If we decide that we want to specify, then we will need to provide a value for the maximum number of clusters. What object would be good for the first decision? Since we are selecting among only a few options, I would suggest a radio button object. This will allow us to provide a list of options from which one will be selected. Ok, but what about the ability to provide the actual maximum number of clusters. For this, we will use a text/numeric field object. This will allow the direct typing of our value.

 

Many other objects are available in the Step Designer for use; however, these are the ones that we will be needing for our Custom Step.

 

STEP 4: Creating the Step in Designer

 

Now we are ready to start our work within the Step Designer. The first thing we will assemble is the DATA tab for our Custom Step. For each object that we drag onto our GUI, we will have a list of properties that we will update on the right side of the screen. These properties control appearance and behaviors for our object. Throughout the process of building the GUI, please be very careful when setting the ID property of each object. You will need to remember exactly what you called an object since this will be its macro name later when we start working with the code creation.

 

  • Starting from SAS Drive, use the applications menu to proceed to Develop Code and Flows. From the menu bar, click New and select Custom Step.
  • The Custom Step area opens into the Designer with Page 1 appearing. On the properties panel, set the ID of the page to data and the label to DATA.

damodl_2_blog3_DATA-1024x201.png

 

  • In the Control Library, scroll down to the Data area and drag Input Table to the DATA page. Set ID to inputdata and Label to "Select table for analysis". Leave the check box next to Required selected.

damodl_3_blog3_inputdata-1024x304.png

 

 

  • Add two Column Selector items to the page. Set the following properties:
    • Column Selector 1 - Set ID to catvars. Make "Select categorical inputs" the label. Under Link to input table, select (inputdata). For Column Type, choose All types.
    • Column Selector 2 - Set ID to intvars. Make "Select continuous inputs" the label. Under Link to input table, select (inputdata). For Column Type, choose Numeric.


damodl_4_blog3_columnselect-1024x305.png

 

You have the option to restrict the type of variables that will appear within the column selector using the Column Type property. This will isolate choices so that when a numeric variable is needed then we will not have someone choose a character variable. The Link property creates a dynamic link between the column selector object and the data set that was chosen. When the column selector is opened, the Custom Step will parse the associated data set and list the appropriate variables from that data set.

 

  • Save the step using the name KCLUSExample.

 

Currently, our Custom Step should look like this when you click the Preview button.

 

damodl_5_blog3_preview.png

 

In part 2 of this blog, we will continue the creation of our Custom Step. We will add our OPTIONS and OUTPUT tabs to the GUI and then add the associated code to the Custom Step. If you would like to investigate Custom Steps further, please visit here to access more information. Also check out the SAS Custom Step repository.

 

Feel free to play around with this Custom Step before viewing part 2 of the blog. Just remember to preserve the Custom Step at this point so we can continue.

 

 

Version history
Last update:
‎11-14-2023 10:34 AM
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