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

Custom Task Tuesday: Advanced Techniques

by SAS Employee OliviaWright ‎04-18-2017 10:54 AM - edited ‎04-18-2017 10:57 AM (1,221 Views)



small.jpgNext week, we will walk through a task that does power analysis for one-way anova. It will be an a large-scale modification of the built-in task for power analysis for pearson correlation. However, there are two elements of custom task development that you need to understand before we dive in that monster of a task. This week's post will help lay the ground work for next week. The first is a control called an Option Table, and the second is the Requirements portion of the VTL code. Both of which will be used several times in our task for allowing the user to provide as many values as they want.


Option Tables

The OptionTable element allows you to organize options into columns. You can choose add the addRemoveRowTools attribute, which will allow the user to add and remove rows from the table. This comes in handy for our use in the power task because for Significance Levels, Sample Sizes, and Power Values, proc power allows the user to specify as many numbers as they want. 


Here's an example of an option table from the built-in Pearson Correlation task:

Screen Shot 2017-04-18 at 10.30.13 AM.png


Here's the Metadata code for the Significance Level option table:

<Option inputType="string" name="alphaGroup">SIGNIFICANCE LEVEL</Option> 
<OptionTable addRemoveRowTools="true" initialNumberOfRows="1" label="Alpha values:" minimumRequiredRows="1" name="alphaTable" noIncompleteRows="true" showColumnHeadings="false">
        <Column defaultValues="0.05" label="Alpha" name="alpha">
            <Option decimalPlaces="1,15" inputType="numbertext" invalidMessage="Enter a number for alpha that is greater than zero and less than 1" maxValue="0.99999999999" minValue="0.00000000001" missingMessage="Enter a number for alpha that is greater than zero and less than 1" promptMessage="Enter a number for alpha that is greater than zero and less than 1" rangeMessage="Enter a number for alpha that is greater than zero and less than 1" required="false"/>


Here's the SAS Code to access the values in the Significance Level option table:

## Alpha
#foreach($item in $alphaTable.rows.values)
   #if ($item.alpha)
#if ($_alpha.size() > 0) alpha=#foreach($item in $_alpha) $item#end#end



 The requirements element allows you to specify a list of conditions (or requirements) that must be met before the task can be run. If the condition is false, a message is printed in green in the SAS Code window, and no code is generated. Each requirement has two pieces, the condition and the message. Conditions can be quickly become complex if your requirement is based on several controls in your task. 


One common use of the requirements element is to require that one value be less than another value. This is helpful in situations where the user needs to specify a maximum and minimum. You do not want the code to generated if the user specifies a maximum that is less than the minimum. 


Here's an example of a requirement from the Pearson Correlation Task that does just that:


<Requirement condition="!(             ($powerBySampleSizePlot == '1') &amp;&amp;              ($solveFor == 'solveforPowerChoice') &amp;&amp;              ($usePlotMinSSValue == '1') &amp;&amp;              ($usePlotMaxSSValue == '1') &amp;&amp;             ($MathTool.toDouble($ssMinValue) &gt; $MathTool.toDouble($ssMaxValue))         )">
    <Message nlsKey="minMaxSampleSizePlotRequirementKey">The maximum sample size for the power by sample size plot cannot be less than the minimum value.</Message>



Join the conversation on Twitter! Use the hashtag #CustomTaskTuesday and tweet Twitter_bird_logo_2012.svg.png@OliviaJWright with your Custom Task comments and questions!



SAS Studio Task GitHub

This post doesn't have a task to download, but check out all other tasks from the Custom Task Tuesday series on our SAS Studio GitHub. 

 Take Me to GitHub!

Your turn
Sign In!

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