We’re smarter together. Learn from this collection of community knowledge and add your expertise.

SAS Studio Custom Task Tuesday: How to Modify an Existing Task

by SAS Employee OliviaWright on ‎01-24-2017 02:15 PM - edited on ‎03-24-2017 05:27 PM by Community Manager (1,184 Views)

CTT.jpgThe approach for this post will be a bit different than the preceding posts in the series. The easiest way to get started with making your own Custom Tasks is to edit an existing task that is already built in to SAS Studio.


There are a bunch of tasks to choose from, and you can do anything from making small edits to using the existing task as a framework for your own task.        


The task that we are going to edit for this post is the Bin Continuous Data task. We are going to add an option to output the scoring data code with the code file= statement for proc hpbin.


Here’s the before and after to show you what our additions will look like:




Step 1: Save the Existing Task to “My Tasks”


The first step to editing an existing task is to add the task to “My Tasks.” This will allow you to make your own modifications and save your own version of the task. Right click on the Bin Continuous Data task and select “Add to My Tasks.”



To edit your version of the task, right click on the Bin Continuous Data under my Tasks and select “Edit.”



Step 2: Make Edits to SAS Code or VTL Code


You’re now ready to make your modifications to the built-in task.  


Editing VTL Code:

The first modification to the VTL code we will want to make is in the Registration section. We want to be sure to note that this is a modified task and update the name and description. Below is my updated Registration section code.


        <Name>Bin Continuous Data Edit</Name>
        <Description>This task is an edited version of the original Bin Continuous Data task. The additional functionality allows the user to download a full mapTable dataset from the binning output. </Description>
            <Link href="http://support.sas.com/documentation/onlinedoc/sasstudio/index.html">SAS Studio User's Guide</Link>
            <Link href="http://support.sas.com/documentation/cdl/en/prochp/66704/HTML/default/viewer.htm#prochp_hpbin_overview.htm">The HPBIN Procedure</Link>
            <Link href="https://communities.sas.com/t5/forums/searchpage/tab/message?q=Custom+Task+Tuesday">Custom Task Tuesday Blog Series </Link>
    <Category>High-Performance Statistics</Category>


The next modification to be made to the Bin Continuous Data Edit VTL code is to add a check box option to allow the user to optionally elect to output code that will score the output dataset. We also need to add a textbox for the user to input the file path in which they would like the output code. This will require small changes to both the Metadata and UI sections of the task. To do this, add the following code:


to the Metadata section:


<Option name="GROUPCHECK" inputType="string">CODE OUTPUT</Option>
<Option name="labelCHECK" inputType="string">Click this checkbox to request the code for scoring output datasets.</Option>
<Option name="chkCODE" defaultValue="0" inputType="checkbox">Score Code Output</Option>
<Option name="labelTEXT" inputType="string">Enter a valid file path for the placement of your output code.</Option>
<Option name="labelTEXT2" inputType="string">Example: C:/Users/olwrig/Desktop/code.sas</Option>
<Option name="textPATH" defaultValue="File path goes here" inputType="inputtext"
            promptMessage="Enter a file path."
            missingMessage="Missing file path.">Input text:</Option>



to the UI section (in the outputTab container):


<Group option="GROUPCHECK" open="true">
      <OptionItem option="labelCHECK"/>
      <OptionItem option="chkCODE"/>
      <OptionItem option="labelTEXT"/>
      <OptionItem option="labelTEXT2"/>
      <OptionItem option="textPATH"/>



The last thing we want to do with the VTL code is make sure that our text box for the file path only shows up if the check box for the code output is checked. To do this, we will use the Dependencies section. This is the first post in this series that has code for this section, so it is not always necessary for creating tasks. Add the following code to what is already in the Dependencies section for the Bin Continuous Data task:


<Dependency condition=" ($chkCODE=='1')">
<Target action="enable" conditionResult="true" option="textPATH"/>
     <Target action="disable" conditionResult="false" option="textPATH"/>
     <Target action="show" conditionResult="true" option="textPATH"/>
     <Target action="hide" conditionResult="false" option="textPATH"/>
     <Target action="enable" conditionResult="true" option="labelTEXT"/>
     <Target action="disable" conditionResult="false" option="labelTEXT"/>
     <Target action="show" conditionResult="true" option="labelTEXT"/>
     <Target action="hide" conditionResult="false" option="labelTEXT"/>
     <Target action="enable" conditionResult="true" option="labelTEXT2"/>
     <Target action="disable" conditionResult="false" option="labelTEXT2"/>
     <Target action="show" conditionResult="true" option="labelTEXT2"/>
     <Target action="hide" conditionResult="false" option="labelTEXT2"/>


Editing SAS Code:

We want to add the code statement to the proc hpbin step. We only want this statement to appear in the code if our code output checkbox is checked. Add the following code before the hpbin run statement:


 #if ( $chkCODE == 1 )
      code file= "$textPATH";


Step 3: Save Your Changes and Run the Task


You’re finished! You just edited an existing SAS Studio task to have your own updated functionality. Click the save.pngbutton to save, then click the run.png button to open the task. Make your selections, then click run.pngagain to watch it run!


Do you have more ideas for modifying the Bin Continuous Data task? Or do you have another built in task that you think could use a modification? Add your ideas in the comments below!


Want to try it yourself?

Get the code from the zip file at the end of this article or from GitHub.

Take Me to GitHub!




Your turn
Sign In!

Want to write an article? Sign in with your profile.