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).
Explanation : Creation of the 'sales' table. Calculation of conditional variables (Status, Ribbon) and positions for graphic markers (ys, yr) based on sales volume.
Copied!
data sales;
Length Status $5 Ribbon $3;
input Name $ Gender $ Sales;
status='Bad';
if sales > 50 then status='Good';
if sales >= 100 then status='Great';
Ribbon=ifc(sales > 110, 'Yes', '');
ys=sales-10;
if ribbon='Yes' then yr=sales-35;
datalines;
Pat Female 100
Bob Male 76
Cody Male 50
Sue Female 120
Val Female 70
;
run;
1
DATA sales;
2
LENGTHSTATUS $5 Ribbon $3;
3
INPUT Name $ Gender $ Sales;
4
5
STATUS='Bad';
6
IF sales > 50THENSTATUS='Good';
7
IF sales >= 100THENSTATUS='Great';
8
9
Ribbon=ifc(sales > 110, 'Yes', '');
10
11
ys=sales-10;
12
IF ribbon='Yes'THEN yr=sales-35;
13
14
DATALINES;
15
Pat Female 100
16
Bob Male 76
17
Cody Male 50
18
Sue Female 120
19
Val Female 70
20
;
21
RUN;
3 Code Block
PROC PRINT
Explanation : Simple display of the created dataset for verification.
Copied!
proc print;run;
1
PROC 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.
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/
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.