BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
david27
Quartz | Level 8

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 "";
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
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 "";



View solution in original post

2 REPLIES 2
Reeza
Super User
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 "";



david27
Quartz | Level 8

@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

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 783 views
  • 0 likes
  • 2 in conversation