BookmarkSubscribeRSS Feed

Customs Task Christmas: Creating a Customizable Christmas Tree

Started ‎12-18-2019 by
Modified ‎12-19-2019 by
Views 6,207

Merry #CustomTaskChristmas!

 

This week I'm sharing a short and sweet custom task to get us all in the holiday spirit. If you celebrate Christmas and don't have your Christmas Tree up yet, we here at SAS want to make it easy.  This Christmas Custom Task will enable you in a matter of seconds to get your tree up and fully decorated with all of the Christmas color ornaments you like.

custom task christmas.png

This task generates a Christmas tree made using PROC SGPLOT and allows users to customize ornament colors, ribbon color,  Christmas tree size (short and fat, tall and skinny, or in the middle), and title.

 

Data Point Creation

This was done in collaboration with one of our outstanding SAS Technical Interns, Laura Federline, who built the data set and SGPLOT code. Here's Laura to explain how she created the plot:

To create the data for our Christmas tree, a web plot digitizer was used. This was a simple way to extract data points from a clip-art image (we used this one). After outlining each part of the Christmas tree, the data was exported to a CSV and given a label corresponding to the tree part.

 

Once imported to SAS, these labels allowed for different parts of the tree to appear differently on the scatter plot. An attribute map was created (inspired by this example) to control the color, symbol, and size of the data points for each part of the tree. Finally, the built-in SAS Studio task "Scatter Plot" was used to create the SGPLOT code, and our Christmas tree was brought to life!

 

point creation.PNG

 

Below is Laura's PROC SGPLOT code before it was Task-ified:

FILENAME REFFILE 'C:/data_christmas.csv';
PROC IMPORT DATAFILE=REFFILE
                DBMS=CSV
                OUT=WORK.tree;
                GETNAMES=YES;
                guessingrows=500;
RUN;
data myattrmap;
                length markercolor $ 9 markersymbol $ 14;
                input ID $ value $ markercolor $ markersymbol $ MARKERSIZE;
                datalines;
myid tree green TriangleFilled 10
myid trunk MOBR SquareFilled 10
myid orn_1 yellow CircleFilled 10
myid orn_2 red CircleFilled 10
myid orn_3 VPAPB CircleFilled 10
myid star gold StarFilled 30
myid ribbon VLIB CircleFilled 10
;
run;
ods graphics / reset width=6.4in height=4.8in imagemap;
proc sgplot data=WORK.TREE dattrmap=myattrmap;
                scatter x=x y=y / group=type attrid=myid;
                xaxis grid;
                yaxis grid;
run;
ods graphics / reset;

Hint: If you don't have SAS Studio to be able to run a Custom Task, use the above code in BASE SAS, SAS Enterprise Guide, or wherever you do your SAS Programming!

 

Custom Task Creation

This task was super simple. We have four groups of controls: FILE LOCATION, COLORS, TITLE, and SIZING. For changing the file location and title, we have a single TEXT BOXES for each. For the colors on the tree, we have 5 COLOR SELECTORS that allow users to change the 3 ornament colors, ribbon color, and background colors. Finally for sizing we have a COMBO BOX (or drop-down) that allows users to select "Short and Fat," "Tall and Skinny" or "In the Middle."

 

Here's the Code Portion of the Task, where I took Laura's SGPLOT code and plugged in Apache Velocity Macro Variables that were associated with all of our task controls.

FILENAME REFFILE '$textFILE';
PROC IMPORT DATAFILE=REFFILE
                DBMS=CSV
                OUT=WORK.tree;
                GETNAMES=YES;
                guessingrows=500;
RUN;
data myattrmap;
                length markercolor $ 9 markersymbol $ 14;
                input ID $ value $ markercolor $ markersymbol $ MARKERSIZE;
                datalines;
myid tree green TriangleFilled 10
myid trunk MOBR SquareFilled 10
myid orn_1 $color1 CircleFilled 10
myid orn_2 $color2 CircleFilled 10
myid orn_3 $color3 CircleFilled 10
myid star gold StarFilled 30
myid ribbon $color4 CircleFilled 10
;
run;

#if ($comboSIZE == "short")
ods graphics / reset width=7in height=5in imagemap;
#end
#if ($comboSIZE == "medium")
ods graphics / reset width=6in height=7.5in imagemap;
#end
#if ($comboSIZE == "tall")
ods graphics / reset width=4in height=7.5in imagemap;
#end

title "$textTITLE";
proc sgplot data=WORK.TREE dattrmap=myattrmap;
styleattrs wallcolor=$color5;
                scatter x=x y=y / group=type attrid=myid;
run;
ods graphics / reset;

 

Download the Task and Data and Try it for Yourself!

The CSV file for the data points and the CTK file for the task are both available for download the Custom Task Tuesday GitHub.

Take Me to GitHub!

Note: If you save the CSV file to your C:/ drive, you will not have to change the default file location in the task. 

 

Share the Custom Task Christmas Magic

Make your own Custom Task Christmas Tree and post it in the comments section of this post, or on Twitter with the hashtag #CustomTaskChristmas

3.PNG1.PNG2.PNG

Know someone else who still needs a tree? Feel free to share this code with anyone you know.  Unlike a real tree, it weighs less than an ounce and can be shipped anywhere in the world with an Internet connection in minutes.

 

Click this button to tweet this article and share with your SAS programmer friends:

Take Me to Twitter!

 

As always, comment here or tweet @OliviaJWright with your Custom Task comments and questions!

Comments

What a festive post! Here's my result. 5EC767CD.PNG

 

I had so much fun helping! Here's my tree:

mytree.png

Version history
Last update:
‎12-19-2019 07:29 AM
Updated by:

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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