Published on :
Général SASHELP

Sans titre

This code is also available in: Deutsch Español Français
The code first configures global graphics options. Then, it filters the `sashelp.class` table for each age (11 to 16 years old) to generate pie charts representing sex distribution. These charts are exported as local PNG files. Finally, these images are reused via `PATTERN` statements to fill the bars of a vertical histogram representing the ages.
Data Analysis

Type : SASHELP


Uses the standard `sashelp.class` table provided with SAS.

1 Code Block
GOPTIONS
Explanation :
Resetting and configuring global graphics parameters (size, resolution, font, PNG output driver).
Copied!
1goptions reset=all gsfname=g device=png xmax=6in ymax=4in xpixels=1800
2ypixels=1200 ftext='Arial' htext=5pct;
3 
2 Code Block
PROC GCHART
Explanation :
Sequential generation of pie charts for each age group. Each chart is saved in a distinct PNG file specified by the `FILENAME` statement. Note: The 'c:\' paths are specific to Windows and will need to be adapted for a SAS Viya (Linux) environment.
Copied!
1filename g 'c:\sex11.png' ; PROC GCHART DATA=sashelp.class ; where age=11 ; pie sex ; RUN ;
2filename g 'c:\sex12.png' ; PROC GCHART DATA=sashelp.class ; where age=12 ; pie sex ; RUN ;
3/* ... Répété pour les âges 13 à 16 ... */
4filename g 'c:\sex16.png' ; PROC GCHART DATA=sashelp.class ; where age=16 ; pie sex ; RUN ;
3 Code Block
PROC GCHART
Explanation :
Creation of the final chart (vertical histogram by age). The `PATTERN` statements map the previously generated PNG images to the chart bars. The `subgroup=age` option ensures that each bar uses the pattern corresponding to its age.
Copied!
1filename g 'c:\vbar.png' ;
2pattern1 image='c:\sex11.png' ;
3pattern2 image='c:\sex12.png' ;
4pattern3 image='c:\sex13.png' ;
5pattern4 image='c:\sex14.png' ;
6pattern5 image='c:\sex15.png' ;
7pattern6 image='c:\sex16.png' ;
8title c=red 'Male ... ' c=green 'Female' ;
9PROC GCHART DATA=sashelp.class ;
10 vbar age / subgroup=age discrete width=20 nolegend ;
11RUN; QUIT;
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.