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

Custom Task Tuesday: Customizing Report Options

by SAS Employee OliviaWright ‎05-23-2017 04:06 PM - edited ‎05-23-2017 04:06 PM (567 Views)

small.jpg

This week's task allows the user to customize certain options for their report that will show up in your report of their results. The user will be able to change the title, color of the title, and add "text decoration" (underline, strike-through, etc) to the title of their report, which will all show up in the output window as well as in the PDF version of the report. It also allows to user to decide whether or not they want dates and page numbers, which will show up in the PDF version of the report. 

 

This task will enable you to do some customization. However, to make other changes like the "theme" of the report, you will need to do that through your Preferences in SAS Studio.

 

Here's the finished version of the task, along with some sample output:

Report Options.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

 

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

Name: Report Options

Description: Allows the user to customize their output reports with title decoration and options to include dates and page numbers.

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

 

Step 3: Fill in Metadata Portion

 

This task has several controls: a dataset selector, a check box selector, a text box, a color selector, and 3 radial button selectors.

As you may know from previous posts in this series, I always copy and paste the code for the controls that I need from the SampleTask that comes built-in with SAS Studio into my New Task. 

 

Below is the full Metadata portion:

 

<Metadata>
    <DataSources>
        <DataSource name="DATASOURCE">
        </DataSource>
    </DataSources>
    <Options>
        <Option inputType="string" name="DATATAB">BASIC OPTIONS</Option>
        <Option inputType="string" name="DATAGROUP">DATA</Option>
        <Option inputType="string" name="DATERADIO">DATE</Option>
        <Option inputType="string" name="labelDATE">Choose whether or not you want the date to be included in the PDF of the report.</Option>
        <Option defaultValue="1" inputType="radio" name="date" variable="radioDATE">Date</Option>
        <Option inputType="radio" name="nodate" variable="radioDATE">No Date</Option>
        <Option inputType="string" name="NUMRADIO">PAGE NUMBER</Option>
        <Option inputType="string" name="labelNUM">Choose whether or not you want page numbers to be included in the PDF of the report.</Option>
        <Option defaultValue="1" inputType="radio" name="number" variable="radioNUM">Number</Option>
        <Option inputType="radio" name="nonumber" variable="radioNUM">No Number</Option>
        <Option inputType="string" name="TITLETEXT">TITLE</Option>
        <Option inputType="string" name="labelTITLE">Enter a title for your report.</Option>
        <Option defaultValue="Title goes here" indent="1" inputType="inputtext" missingMessage="Missing title." name="textTITLE" promptMessage="Enter a title." required="true">Title:</Option>
        <Option inputType="string" name="labelTITLEDEC">Choose a title text decoration.</Option>
        <Option defaultValue="1" indent="1" inputType="radio" name="none" variable="radioTITLEDEC">None</Option>
        <Option indent="1" inputType="radio" name="underline" variable="radioTITLEDEC">Underline</Option>
        <Option indent="1" inputType="radio" name="overline" variable="radioTITLEDEC">Overline</Option>
        <Option indent="1" inputType="radio" name="line_through" variable="radioTITLEDEC">Line Through</Option>
	<Option inputType="string" name="labelCOLOR">Select a color for your title color.</Option>
	<Option defaultValue="black" indent="1" inputType="color" name="colorTITLE">Choose a color</Option>
	<Option inputType="string" name="GROUPCHECK">CONTENT</Option>
	<Option inputType="string" name="labelCHECK">Check the boxes of the output you would like to include in your report.</Option>
	<Option defaultValue="0" inputType="checkbox" name="chkFREQ">Proc Freq</Option>
	<Option defaultValue="0" inputType="checkbox" name="chkMEANS">Proc Means</Option>
	<Option defaultValue="0" inputType="checkbox" name="chkPRINT">Proc Print</Option>
    </Options>
</Metadata>

 

Step 4: Fill in UI Portion

 

The UI portion is where you specify the order of all of the controls you listed in the metadata portion. We will have corresponding code in the UI section for each control in the Metadata section. This code can also be copied and pasted from the Sample Task just as we did with the Metadata porton.

 

The full UI portion is below:

 

<UI>
    <Container option="DATATAB">
        <Group open="true" option="DATAGROUP">
            <DataItem data="DATASOURCE"/>
        </Group>
	<Group open="true" option="GROUPCHECK">
	    <OptionItem option="labelCHECK"/>
	    <OptionItem option="chkFREQ"/>
	    <OptionItem option="chkMEANS"/>
	    <OptionItem option="chkPRINT"/>
	</Group>
	<Group open="true" option="TITLETEXT">
	    <OptionItem option="labelTITLE"/>
	    <OptionItem option="textTITLE"/>
	    <OptionItem option="labelTITLEDEC"/>
            <OptionItem option="none"/>
	    <OptionItem option="underline"/>
	    <OptionItem option="overline"/>
	    <OptionItem option="line_through"/>
	    <OptionItem option="labelCOLOR"/>
	    <OptionItem option="colorTITLE"/>
	</Group>
	<Group open="true" option="DATERADIO">
	    <OptionItem option="labelDATE"/>
	    <OptionItem option="date"/>
	    <OptionItem option="nodate"/>
	</Group>
	<Group open="true" option="NUMRADIO">
	    <OptionItem option="labelNUM"/>
	    <OptionItem option="number"/>
	    <OptionItem option="nonumber"/>
	</Group>
    </Container>
</UI>

 

 

Step 5: Fill in Code Template Portion

 

The Code Template is what makes the velocity code work with your SAS code. You paste in the SAS code that you know works, and fill in the blanks you want filled with information from the custom task user with Velocity Macro Variables. These begin with a dollar sign ($). The velocity macro variables in our code are: $radioDATE, $radioNUM, $radioTITLEDEC, $colorTITLE, $textTITLE, $DATASOURCE, $chkFREQ, $chkMEANS, and $chkPRINT.

 

Below is the full Code Template Portion:

 

options $radioDATE $radioNUM;

ods escapechar='^';
title "^{style [textdecoration=$radioTITLEDEC color=$colorTITLE]$textTITLE }";

%macro analysis;
%if $chkFREQ = 1 %then %do;
	proc freq data=$DATASOURCE;
	run;
%end;

%if $chkMEANS = 1 %then %do;
	proc means data=$DATASOURCE;
	run;
%end;

%if $chkPRINT = 1 %then %do;
	proc print data=$DATASOURCE;
	run;
%end;
%mend analysis;
%analysis;

title;
ods _all_ close; 

 

 

Step 6: Run the Task

 

You’re finished! You created a custom user interface to do customize report options for your output. 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!

 

 

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!

Contributors
Your turn
Sign In!

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