Hello,
Please see the code below:
In the below code I create two charts. One using Proc Freq and other using Proc GChart.
I want a chart that is generated by Proc Freq, but by using Proc GChart.
I have put necessary titles in the code.
Please advise!
Thank You
data have;
input variable1 yyyymm;
informat yyyymm yymmn6.;
format yyyymm yymmn6.;
datalines;
. 202101
. 202101
0 202101
0 202101
0 202101
0 202102
0 202102
. 202102
0 202102
1 202102
0 202103
0 202103
0 202103
0 202103
0 202103
0 202104
0 202104
0 202104
1 202104
0 202104
0 202105
0 202105
0 202105
1 202105
1 202105
0 202106
. 202106
. 202106
. 202106
1 202106
;run;
proc format ;
value nmissfmt
.="Missing"
;
run;
ods graphics on;
proc freq data=have;
Title "Want the below chart using Proc GChart";
format variable1 nmissfmt.;
tables variable1*yyyymm / missing norow nocol nopercent out=freq_output
plots=freqplot(twoway=stacked orient=Horizontal );
run;
title "";
data freq_output2(rename=(t=variable1));
set freq_output(rename=( variable1 = _tempvar_));
format t nmissfmt.;
t=_tempvar_;
drop _tempvar_;
run;
title "";
proc gchart data=freq_output2;
Title "This is what I get using GChart. I want the chart to look like from Proc Freq up Above.";
format variable1 nmissfmt.;
hbar variable1 / group=yyyymm
subgroup=variable1
sumvar=count
;
run;
quit;
title "";
proc sgplot data=have;
hbar yyyymm / group=variable1 stat=freq missing;
format variable1 nmissfmt.;
label variable1 ='Variable1';
yaxis reverse;
run;
For further customization see:
https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/grstatproc/n0p7vdd69sgf3wn1479qxqxuryrt.htm
@david27 wrote:
Hello,
Please see the code below:
In the below code I create two charts. One using Proc Freq and other using Proc GChart.
I want a chart that is generated by Proc Freq, but by using Proc GChart.
I have put necessary titles in the code.
Please advise!
Thank You
data have; input variable1 yyyymm; informat yyyymm yymmn6.; format yyyymm yymmn6.; datalines; . 202101 . 202101 0 202101 0 202101 0 202101 0 202102 0 202102 . 202102 0 202102 1 202102 0 202103 0 202103 0 202103 0 202103 0 202103 0 202104 0 202104 0 202104 1 202104 0 202104 0 202105 0 202105 0 202105 1 202105 1 202105 0 202106 . 202106 . 202106 . 202106 1 202106 ;run; proc format ; value nmissfmt .="Missing" ; run; ods graphics on; proc freq data=have; Title "Want the below chart using Proc GChart"; format variable1 nmissfmt.; tables variable1*yyyymm / missing norow nocol nopercent out=freq_output plots=freqplot(twoway=stacked orient=Horizontal ); run; title ""; data freq_output2(rename=(t=variable1)); set freq_output(rename=( variable1 = _tempvar_)); format t nmissfmt.; t=_tempvar_; drop _tempvar_; run; title ""; proc gchart data=freq_output2; Title "This is what I get using GChart. I want the chart to look like from Proc Freq up Above."; format variable1 nmissfmt.; hbar variable1 / group=yyyymm subgroup=variable1 sumvar=count ; run; quit; title "";
proc sgplot data=have;
hbar yyyymm / group=variable1 stat=freq missing;
format variable1 nmissfmt.;
label variable1 ='Variable1';
yaxis reverse;
run;
For further customization see:
https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/grstatproc/n0p7vdd69sgf3wn1479qxqxuryrt.htm
@david27 wrote:
Hello,
Please see the code below:
In the below code I create two charts. One using Proc Freq and other using Proc GChart.
I want a chart that is generated by Proc Freq, but by using Proc GChart.
I have put necessary titles in the code.
Please advise!
Thank You
data have; input variable1 yyyymm; informat yyyymm yymmn6.; format yyyymm yymmn6.; datalines; . 202101 . 202101 0 202101 0 202101 0 202101 0 202102 0 202102 . 202102 0 202102 1 202102 0 202103 0 202103 0 202103 0 202103 0 202103 0 202104 0 202104 0 202104 1 202104 0 202104 0 202105 0 202105 0 202105 1 202105 1 202105 0 202106 . 202106 . 202106 . 202106 1 202106 ;run; proc format ; value nmissfmt .="Missing" ; run; ods graphics on; proc freq data=have; Title "Want the below chart using Proc GChart"; format variable1 nmissfmt.; tables variable1*yyyymm / missing norow nocol nopercent out=freq_output plots=freqplot(twoway=stacked orient=Horizontal ); run; title ""; data freq_output2(rename=(t=variable1)); set freq_output(rename=( variable1 = _tempvar_)); format t nmissfmt.; t=_tempvar_; drop _tempvar_; run; title ""; proc gchart data=freq_output2; Title "This is what I get using GChart. I want the chart to look like from Proc Freq up Above."; format variable1 nmissfmt.; hbar variable1 / group=yyyymm subgroup=variable1 sumvar=count ; run; quit; title "";
@Reeza : Thank You very much for the solution. I accidentally selected my reply as solution. How do i correct it?
Thank You for teaching me that i dont have to do frequency first to create the chart. I can get it from raw table itself !!!!
Regards
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.