BookmarkSubscribeRSS Feed

SAS Studio Custom Task Tuesday: Itsy Bitsy Data Analysis

Started ‎02-28-2017 by
Modified ‎08-04-2021 by
Views 2,963

This week’s task for Custom Task Tuesday allows the user to do data analysis on “itsy bitsy” data. In statistics, the types of analyses you can do on large datasets are not the same as the types of analyses you can do on small datasets due to the inability to fulfill basic statistical assumptions with small data.

small.jpg

 

One type of test that is great for tiny datasets is Fisher’s exact test to determine whether there is a relationship between two variables, instead of a Chi-squared test which would be used for larger datasets.

 

The task we are constructing today will allow the user to select their datasets and two variables on which to perform the Fisher’s exact test. The results will include a print out of the two variables selected in addition to results of the Fisher’s exact test.

 

This is what the task will look like when we are finished, along with some sample output:

 

itsy bitsy.PNG

 

Step 1: Getting Started

 new task.png

In SAS Studio, under the Task and Utilities section, open a “New Task” as well as the “Sample Task.” We will copy and paste the necessary Velocity Template code from the Sample Task to our task.

 

Step 2: Naming and Saving the Task

 

Name: Itsy Bitsy Data Analysis

Description: Analyze itsy bitsy data using Fisher’s exact test.

At the top of the VTL code for your New Task, you will need to fill in the Name and Description portions as shown below:

 

 1.png

 

After you’ve done that, you should save this task to your My Tasks folder, so you don’t lose it. Click theedity.pngbutton in the upper left corner of the task to bring up this option screen:

 

 2.png

 

Step 3: Creating the Metadata Portion of the Task

 

The easiest way to create the CTM portion of the task is to steal VTL code from the Sample Task. From looking at our “finished product,” you can see that we are going to use one dataset selector and two role selectors. Find the code that corresponds with a combobox in the Metadata section of the Sample Task, and copy and paste them into the same place in your task. Edit to code you copied to correspond with what we want as our finished product. With the role selectors, we want to make sure we have the maxVars and minVars both equal to 1, as Fisher’s exact test requires exactly two variables.

 

Your finished metadata portion should look something like this:

 

<Metadata>
       <DataSources>
          <DataSource name="DATASOURCE">
              <Roles>
                  <Role type="N" maxVars="1" order="true" minVars="1" name="OPTNVAR1" exclude="VAR">Variable 1 for Fisher's Exact Test:</Role>
                  <Role type="N" maxVars="1" order="true" minVars="1" name="OPTNVAR2" exclude="VAR">Variable 2 for Fisher's Exact Test:</Role>
              </Roles>
          </DataSource>
       </DataSources>
       <Options>
          <Option name="DATATAB" inputType="string">DATA</Option>
          <Option name="DATAGROUP" inputType="string">DATA</Option>
          <Option inputType="string" name="label">COPY dataset is created in Work library that is a copy of your input dataset.</Option>
          <Option name="ROLESGROUP" inputType="string">FISHER'S EXACT TEST</Option>
       </Options>
</Metadata>

 

Step 4: Creating the UI Portion of the Task

 

Recall: each object in the metadata portion will have corresponding code in the UI portion. The UI portion determines the ordering of the display of the task. Just like before, find the code that correspond with the objects we need (one dataset selector, two role selectors) in the UI section of the Sample Task, and copy and paste them into the same place in your task. Edit to code you copied to correspond with what we want as our finished product.

 

This is what your finished UI portion should look like:

 

<UI>
<Container option="DATATAB">
              <Group option="DATAGROUP" open="true">
                     <OptionItem option="label"/>
                     <DataItem data="DATASOURCE"/>
              </Group>
              <Group option="ROLESGROUP" open="true">
                     <RoleItem role="OPTNVAR1"/>
                     <RoleItem role="OPTNVAR2"/>
              </Group>
       </Container>
</UI>

 

Step 5: Creating the Code Template Portion of the Task

 

In your SAS code, you will reference the Velocity macro variables that we created above ($DATASOURCE, $OPTNVAR1, $OPTNVAR2). This is how you make the interface work with and control your SAS code, so this is the most important part. This SAS code sorts the dataset and performs Fisher's exact test on the data.

 

This is what your final Code Template portion should look like:

 

data COPY;
       set $DATASOURCE;
run;                       
proc sort data = COPY;
by #if( $OPTNVAR1.size() > 0 )#foreach( $item in $OPTNVAR1 )$item #end #end
  #if( $OPTNVAR2.size() > 0 )#foreach( $item in $OPTNVAR2 )$item #end #end  ;
run;
proc print data = COPY;
  var #if( $OPTNVAR1.size() > 0 )#foreach( $item in $OPTNVAR1 )$item #end #end
  #if( $OPTNVAR2.size() > 0 )#foreach( $item in $OPTNVAR2 )$item #end #end  ;
run;
proc freq data = COPY;
  tables #if( $OPTNVAR1.size() > 0 )#foreach( $item in $OPTNVAR1 )$item #end #end
  * #if( $OPTNVAR2.size() > 0 )#foreach( $item in $OPTNVAR2 )$item #end #end
  / fisher noprint;
run;

 

Step 6: Run the Task

 

You’re finished! You created a custom user interface to do analysis (means and fisher’s exact test) on itsy bitsy data. Click the save.pngbutton to save, then click the run.pngbutton to open the task. Make your selections, then click run.pngagain to watch it run!

 

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!

Version history
Last update:
‎08-04-2021 01:44 PM
Updated by:

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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