The script initializes a macro variable `name` to 'col1'. It then defines an `odsout` `fileref` to point to the current directory. A `DATA STEP` is used to create a `my_data` dataset with categories, series, and amounts. The output is configured to generate an HTML file (`col1.htm`) and a PNG image via ODS HTML and ODS Graphics. `PROC SGPLOT` is then called to create a grouped vertical bar chart, visualizing the sum of amounts by category, grouped by series, with custom titles and axis attributes.
Data Analysis
Type : INTERNAL_CREATION
The data is directly integrated into the SAS script via a `datalines` block within a `DATA STEP` named `my_data`. No external data source or SASHELP library is used for the main input of the chart.
1 Code Block
DATA STEP Data
Explanation : This `DATA STEP` block creates the `my_data` dataset that will be used for the chart. It reads four observations with the variables `CATEGORY`, `SERIES` (character, length 3-11), and `AMOUNT` (numeric) from the `datalines`.
Copied!
data my_data;
input CATEGORY SERIES $ 3-11 AMOUNT;
datalines;
1 Series A 5
2 Series A 7.8
1 Series B 9.5
2 Series B 5.9
;
run;
1
DATA my_data;
2
INPUT CATEGORY SERIES $ 3-11 AMOUNT;
3
DATALINES;
4
1 Series A 5
5
2 Series A 7.8
6
1 Series B 9.5
7
2 Series B 5.9
8
;
9
RUN;
2 Code Block
PROC SGPLOT
Explanation : This block initializes the `name` macro variable, then configures ODS output to generate an HTML file (`col1.htm`) and PNG graphics in the current directory. `PROC SGPLOT` is then invoked to create a grouped vertical bar chart from the `my_data` dataset. The bars represent the sum of `AMOUNT` for each `CATEGORY`, grouped by `SERIES`. Style, color, and axis options are applied to enhance the visualization. The chart is exported as a PNG image and embedded in the HTML file.
title2 color=gray33 ls=0.5 h=17pt "Compares values across categories";
15
16
PROC SGPLOTDATA=my_data noautolegend;
17
styleattrs datacolors=(cx9999ff cx993366);
18
vbar category / response=amount stat=sum
19
group=series groupdisplay=cluster
20
outlineattrs=(color=black) nostatlabel;
21
yaxis
22
values=(0 to 10BY2)
23
labelattrs=(size=16pt weight=bold color=gray33)
24
valueattrs=(size=16pt weight=bold color=gray33)
25
offsetmax=0 grid minor minorcount=1;
26
xaxis
27
labelattrs=(size=16pt weight=bold color=gray33)
28
valueattrs=(size=16pt weight=bold color=gray33)
29
labelpos=right;
30
RUN;
31
32
QUIT;
33
ODS HTML CLOSE;
34
ODS 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.
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.