Published on :
Visualization CREATION_INTERNE

Zodiac Sign Frequency with Unicode Symbols

This code is also available in: Deutsch Español Français
Awaiting validation
The script begins by creating an internal dataset 'zodiacs' containing zodiac sign names and their respective frequencies. Then, it defines a custom format 'zodiacSymbol' that associates each sign with its corresponding Unicode symbol. A STATGRAPH template, 'unicodeUDF', is then created to specify the structure of a bar chart where the X-axis labels will use this Unicode format. Finally, PROC SGRENDER is used to produce the graph based on the defined template and 'zodiacs' data, also formatting the frequency variable as percentages for better readability.
Data Analysis

Type : CREATION_INTERNE


The data used ('zodiacs') is created directly within the SAS script via a DATA step and the DATALINES statement, meaning it is internal to the script and does not come from an external source.

1 Code Block
DATA STEP Data
Explanation :
This block creates the 'zodiacs' dataset. It defines the 'Sign' variable as a 12-character string and 'Frequency' as a number. The data is then read from the datalines directly integrated into the script.
Copied!
1DATA zodiacs;
2 LENGTH Sign $12;
3 INPUT Sign $ Frequency;
4 DATALINES;
5 Scorpio 0.094
6 Virgo 0.090
7 Gemini 0.090
8 Sagittarius 0.073
9 Leo 0.069
10 Aquarius 0.055
11 ;
12RUN;
2 Code Block
PROC FORMAT
Explanation :
This block uses PROC FORMAT to define a user-defined format named '$zodiacSymbol'. This format is essential for mapping each zodiac sign to its corresponding Unicode symbol. This allows graphic symbols to be displayed directly on the chart axis.
Copied!
1PROC FORMAT;
2 value $ zodiacSymbol
3 'Scorpio' = "(*ESC*){unicode '264F'x}" /* NOTE: unicode expects U16BE */
4 'Virgo' = "(*ESC*){unicode '264D'x}"
5 'Gemini' = "(*ESC*){unicode '264A'x}"
6 'Sagittarius' = "(*ESC*){unicode '2650'x}"
7 'Leo' = "(*ESC*){unicode '264C'x}"
8 'Aquarius' = "(*ESC*){unicode '2652'x}"
9 ;
10RUN;
3 Code Block
PROC TEMPLATE
Explanation :
This block defines a STATGRAPH template called 'unicodeUDF'. It configures a bar chart (barChartParm) with a title. The crucial option is 'xAxisOpts', which uses the '$zodiacSymbol' format defined previously to display Unicode symbols on the X-axis, thereby enhancing the visualization of categories.
Copied!
1PROC TEMPLATE;
2 define statgraph unicodeUDF;
3 beginGraph;
4 entryTitle "Zodiac Frequency: Unicode Tick Values using User Defined Format";
5 layout overlay / xAxisOpts=(tickValueAttrs=GraphUnicodeText(size=14)
6 display=(tickvalues)
7 discreteOpts=(tickValueFormat=$zodiacSymbol.)
8 );
9 barChartParm x=Sign y=Frequency / dataTransparency=0.3
10 dataLabel=Sign;
11 endLayout;
12 endGraph;
13 END;
14RUN;
4 Code Block
PROC SGRENDER
Explanation :
This block uses PROC SGRENDER to generate the chart based on the 'unicodeUDF' template and the 'zodiacs' dataset. The 'format Frequency percent.' statement applies a percentage format to the 'Frequency' variable, making the values more intuitive in the graph.
Copied!
1 
2PROC SGRENDER template=unicodeUDF
3DATA=zodiacs;
4FORMAT Frequency percent. ;
5RUN;
6 
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.