The 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:
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.”
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.
<Registration>
<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>
<Procedures>HPBIN</Procedures>
<Version>3.5</Version>
<Links>
<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>
</Links>
<Category>High-Performance Statistics</Category>
</Registration>
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"
indent="1"
required="true"
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"/>
</Group>
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"/>
</Dependency>
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";
#end
You’re finished! You just edited an existing SAS Studio task to have your own updated functionality. Click the button to save, then click the button to open the task. Make your selections, then click again 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!
Get the code from the zip file at the end of this article or from GitHub.
Thought I'd try my question here, before I pose a new question to SAS Community board.
I've been stuck trying to modify a task template I created. I'm using SAS Studio 4.4, and I've saved my own task as .ctm file. But when I open it again, it opens as .ctk file, which is uneditable.
I tried the steps you describe above, but I'm stuck at Step 1. I saved the task to My Tasks, but when I right-click it in My Tasks, I don't see Edit. The only options I see are: Open Task, Copy Task to Explorer, Add to My Favorites, Hide, Delete, Properties.
Any idea why? Is there a permission or autorization I need to request from our SAS Admin?
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning and boost your career prospects.