Published on :
Reporting CREATION_INTERNE

Sales Visualization with Custom Image Markers

This code is also available in: Deutsch Español Français
Awaiting validation
This script creates a 'sales' dataset containing sales performance by gender. It then uses the SGPLOT procedure to visualize this data. The unique feature lies in the use of the SYMBOLIMAGE statement to associate external images (local PNG files) with status values ('Bad', 'Good', 'Great'), thereby creating conditional visual highlighting. The script generates two versions of the chart, the second adding additional 'ribbon' logic.
Data Analysis

Type : CREATION_INTERNE


Data is created manually via the DATALINES statement in the DATA step. Note: The script refers to Windows image paths (C:\) which will need to be adapted for a SAS Viya (Linux) environment.

1 Code Block
ODS
Explanation :
Configuration of ODS (Output Delivery System) output to define the graphics output path and resolution (DPI).
Copied!
1%let gpath='.';
2%let dpi=200;
3ods html close;
4ods listing gpath=&gpath image_dpi=&dpi;
2 Code Block
DATA STEP Data
Explanation :
Creation of the 'sales' table. Calculation of conditional variables (Status, Ribbon) and positions for graphic markers (ys, yr) based on sales volume.
Copied!
1DATA sales;
2 LENGTH STATUS $5 Ribbon $3;
3 INPUT Name $ Gender $ Sales;
4 
5 STATUS='Bad';
6 IF sales > 50 THEN STATUS='Good';
7 IF sales >= 100 THEN STATUS='Great';
8 
9 Ribbon=ifc(sales > 110, 'Yes', '');
10 
11 ys=sales-10;
12 IF ribbon='Yes' THEN yr=sales-35;
13 
14 DATALINES;
15Pat Female 100
16Bob Male 76
17Cody Male 50
18Sue Female 120
19Val Female 70
20;
21RUN;
3 Code Block
PROC PRINT
Explanation :
Simple display of the created dataset for verification.
Copied!
1PROC PRINT;RUN;
4 Code Block
PROC SGPLOT
Explanation :
Creation of the first combined chart. Uses VBARPARM for bars and SCATTER to place images defined by SYMBOLIMAGE based on status.
Copied!
1ods graphics / reset attrpriority=none width=5in height=3in imagename='Conditional';
2title 'Sales and Status by Sales Person';
3PROC SGPLOT DATA=sales;
4 symbolimage name=bad image="C:\Sad_Tran.png" / scale=1;
5 symbolimage name=good image="C:\Happy_Tran.png" / scale=1;
6 symbolimage name=great image="C:\VeryHappy_Tran.png" / scale=1;
7 styleattrs datasymbols=(great good bad) datacolors=(pink cx4f5faf);
8 
9 vbarparm category=name response=sales / group=gender dataskin=gloss
10 filltype=gradient groupdisplay=cluster;
11 scatter x=name y=ys / group=STATUS markerattrs=(size=30);
12 yaxis offsetmin=0 offsetmax=0 grid;
13 xaxis display=(nolabel) offsetmin=0.1 offsetmax=0.1;
14RUN;
5 Code Block
PROC SGPLOT
Explanation :
Creation of the second chart. Adds an additional layer to display a ribbon (image 'rib') for top sales, in addition to status emoticons.
Copied!
1ods graphics / reset attrpriority=none width=5in height=3in imagename='Conditional2';
2title 'Sales and Status by Sales Person';
3PROC SGPLOT DATA=sales;
4 symbolimage name=bad image="C:\Sad_Tran.png";
5 symbolimage name=good image="C:\Happy_Tran.png";
6 symbolimage name=great image="C:\VeryHappy_Tran.png";
7 symbolimage name=rib image="C:\Blue_Ribbon_Tran.png" / rotate=20;
8 styleattrs datasymbols=(great good bad rib) datacolors=(pink cx4f5faf);
9 
10 vbarparm category=name response=sales / fillattrs=(color=white);
11 vbarparm category=name response=sales / group=gender dataskin=gloss
12 filltype=gradient groupdisplay=cluster;
13 scatter x=name y=ys / group=STATUS markerattrs=(size=30);
14 scatter x=name y=yr / markerattrs=graphdata4(size=75) discreteoffset=0.25;
15 yaxis offsetmin=0 offsetmax=0 grid;
16 xaxis display=(nolabel) offsetmin=0.1 offsetmax=0.1;
17RUN;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
Copyright Info : http://blogs.sas.com/content/graphicallyspeaking/2015/04/12/conditional-highlighting-2/