Hello
I want to create bar chart of following information in table "summary_b"
x-axis will have Y_Cat categories
y-axis will display PCT_SUM_Y
I want also to learn how to create this bar chart from original raw data (RawTbl table)
thank you
Data RawTbl;
input ID group $ Y;
cards;
1 a 10
2 a 20
3 a 30
4 b 15
5 b 30
6 b 45
7 c 60
8 c 75
9 c 90
10 c 80
;
run;
/*chart1*/
ods graphics on;
proc freq data=RawTbl;
tables group / plots=FreqPlot(scale=Percent) out=Freq1Out; /* save Percent variable */
run;
/*chart2*/
proc format;
value ffmt
0-40='0-40'
40-80='40-80'
80-100='80-100'
;
run;
ods graphics on;
proc freq data=RawTbl;
tables Y / plots=FreqPlot(scale=Percent) out=Freq1Out; /* save Percent variable */
format Y ffmt.;
run;
/*chart3*/
PROC SQL;
create table summary_a as
select put(Y,ffmt.) as Y_Cat,
sum(Y) as Sum_Y
from RawTbl
group by calculated Y_Cat
;
QUIT;
PROC SQL;
create table summary_b as
select *,
Sum_Y/sum(Sum_Y) as PCT_SUM_Y format=percent9.1
from summary_a
;
QUIT;
/*Now I want to create bar chart of Y_Cat (x-axis) ,PCT_SUM_Y (y-axis)*/
Hi @Ronein
Here is a way to create a hbar from summary_b:
axis1 label=none;
axis2 label=('your label') order=0 to 1 by 0.1 ;
title1 'Your title';
proc gchart data=summary_b;
hbar Y_Cat / sumvar = PCT_SUM_Y maxis=axis1 raxis=axis2 nostats;
run;
Otherwise, you can simplify your code:
proc format;
value ffmt
0-40='0-40'
40-80='40-80'
80-100='80-100'
;
run;
Data RawTbl_bis;
set rawtbl;
format Y_class ffmt.;
Y_class = Y;
run;
proc tabulate data=RawTbl_bis out=summary_stat;
var Y;
class Y_class;
tables Y_class*(Y* (sum pctsum));
format Y ffmt.;
run;
axis1 label=none;
axis2 label=('your label') order=0 to 100 by 10 ;
title1 'Your title';
proc gchart data=summary_stat;
hbar Y_class / sumvar = Y_pctsum_0_Y maxis=axis1 raxis=axis2 ;
run;
Create another variable and use that in the data set as the weight. A view would also work.
Data RawTbl;
input ID group $ Y;
Z = Y;
cards;
1 a 10
2 a 20
3 a 30
4 b 15
5 b 30
6 b 45
7 c 60
8 c 75
9 c 90
10 c 80
;
run;
/*chart2*/
proc format;
value ffmt
0-40='0-40'
40-80='40-80'
80-100='80-100'
;
run;
proc freq data=rawtbl;
table y / plots=freqplot (scale=percent);
weight z;
format y ffmt.;
run;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.