Published on :
Reporting CREATION_INTERNE

3D Bubble Plot Generation

This code is also available in: Deutsch Español Français
Awaiting validation
The script initializes a macro variable to name the HTML output file and assigns the current directory to the 'odsout' fileref. It then creates a dataset named 'my_data' using inline data (datalines). The ODS (Output Delivery System) is configured to generate HTML output and a PNG image of the plot, with custom titles. The SGPLOT procedure is used to create the bubble plot, with style options, grouping by series, and detailed customization of the X and Y axes.
Data Analysis

Type : CREATION_INTERNE


The 'my_data' dataset is created directly in the SAS script via a DATA STEP and DATALINES instructions, providing the variables 'series', 'x', 'y', and 'value'.

1 Code Block
MACRO VARIABLE / FILENAME
Explanation :
Defines the macro variable `name` to name the HTML output file and assigns the current directory to the `odsout` fileref for output file management.
Copied!
1%let name=bub2;
2 
3/*
4Set your current-working-directory (to read/write files), if you need to ...
5%let rc=%sysfunc(dlgcdir('c:\someplace\public_html'));
6*/
7filename odsout '.';
2 Code Block
DATA STEP Data
Explanation :
Creates the 'my_data' dataset in memory using a DATA STEP. It defines the variables 'series', 'x', 'y', and 'value' from the data provided directly via `datalines` instructions.
Copied!
1DATA my_data;
2LENGTH color $ 8;
3INPUT series $ 1-1 x y value;
4DATALINES;
5A 1.0 1.0 .65
6A 2.0 0.9 0.3
7B 1.4 2.3 .65
8B 2.2 1.4 0.3
9;
10RUN;
3 Code Block
ODS / TITLE
Explanation :
This block manages the Output Delivery System (ODS) configuration. It closes the default LISTING output and opens an ODS HTML destination to write the plot to an HTML file. ODS Graphics options are configured to generate a PNG image of the plot with specified dimensions. Custom titles are defined for the plot with specific colors and font sizes.
Copied!
1ODS LISTING CLOSE;
2ODS HTML path=odsout body="&name..htm"
3 (title="SGplot Bubble Plot (3D)")
4 style=htmlblue;
5 
6ods graphics / imagefmt=png imagename="&name"
7 width=800px height=600px noborder imagemap;
8 
9title1 color=gray33 ls=0.0 h=23pt "Bubble Plot";
10title2 color=gray33 ls=0.5 h=17pt "With 3D Shading";
4 Code Block
PROC SGPLOT
Explanation :
Executes the SGPLOT procedure to create a 3D bubble plot. The 'my_data' dataset is used. Bubble colors are defined, and bubbles are grouped by the 'series' variable. X and Y axes are fully customized with value ranges, labels, text attributes, and grids. Bubble size is proportional to the 'value' variable.
Copied!
1PROC SGPLOT DATA=my_data aspect=1 noautolegend;
2styleattrs datacolors=(cx9999ff cx993366);
3bubble x=x y=y size=value / group=series proportional
4 bradiusmax=70px lineattrs=(color=gray33) /*transparency=.5*/
5 dataskin=sheen;
6yaxis
7 values=(0 to 3 BY 1) label='Y Axis'
8 labelattrs=(size=16pt weight=bold color=gray33)
9 valueattrs=(size=16pt weight=bold color=gray33)
10 offsetmin=0 offsetmax=0 grid minor minorcount=1;
11xaxis
12 values=(0 to 3 BY 1) label='X Axis'
13 labelattrs=(size=16pt weight=bold color=gray33)
14 valueattrs=(size=16pt weight=bold color=gray33)
15 offsetmin=0 offsetmax=0 grid minor minorcount=1;
16RUN;
17 
18QUIT;
5 Code Block
ODS CLOSURE
Explanation :
Closes the ODS HTML destination, thereby stopping writing to the HTML file, and reactivates the default ODS LISTING destination.
Copied!
1ODS HTML CLOSE;
2ODS LISTING;
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.