BookmarkSubscribeRSS Feed
babykxy
Calcite | Level 5

I want to generate a bar chart show percentage and count in bar plot. as below image

I  also want date variable as order.

data plot1 ;
input month $1-10 year $10-14 L2011_12 16-19 L2011_3 20-22 L2014_12 23-27 L2014_3 29-32 L2017 35-38 NYS 39-44 ;
datalines;
March     2018	24	25	187	8455	20	0	  
June      2018	2	5	136	8907	42	0	  
September 2018	14	7	135	8597	73	74	   
December  2018	0	0	134	7930	73	613 	
March     2019	0	0	139	7446	77	1454	
;
run;

proc sort data= plot1; by year month; run;
proc transpose data=plot1 out=long1;
by year month; run;
data long2;
set long1;
date= month||year; run;
 
proc sgplot data =long2 noborder;
styleattrs datacolors=(Firebrick big vpap deepskyblue ) ;
vbar date / response= col1
group=_NAME_ fill barwidth=0.4 seglabel seglabelattrs=(color=black size=8 )
seglabel datalabel
baselineattrs=(thickness=0)
outlineattrs=(color=cx3f3f3f);
xaxis display=(nolabel noline noticks);
yaxis display=(noline noticks) grid;
run;

doc.png

4 REPLIES 4
ballardw
Super User

Please post code in to a code box opened on the forum with the {I}, especially a data step that reads fixed column data. The message windows remove white space and may insert other characters so that the data step as posted will not run.

 

Create an actual DATE valued variable so that things will sort properly, apply a format you want:

data example;
   month='September';
   year ='2018';
   date = input (catx(' ','1',month,year),anydtdte18.);
   format date monyy7.;
run;

If you start using the full month name the width of the text may have issues fitting depending on the actual months involved and how many are involved.

babykxy
Calcite | Level 5

thank you! it is works!

I edited it! Thank you for you reminding me!

ballardw
Super User

What percentages do you expect to show? You will likely need to add something to the data and display.

 

 

babykxy
Calcite | Level 5
data data ;
input  month $1-10 year $10-14 level $15-24  count 28-34 precent 35-42;
datalines;
March     2018	L2011_12	24	  0.003
March     2018	L2011_3	    25	  0.003
March     2018	L2014_12	187	  0.021
March     2018	L2014_3	    8455  0.971
March     2018	L2017	    20	  0.002
March     2018	NYSPCMH	    0	  0
June      2018	L2011_12	2	  0
June      2018	L2011_3	    5	  0.001
June      2018	L2014_12	136	  0.015
June      2018	L2014_3	    8907  0.98
June      2018	L2017	    42	  0.005
June      2018	NYSPCMH  	0	  0
September 2018	L2011_12	14	  0.002
September 2018	L2011_3	    7	  0.001
September 2018	L2014_12	135	  0.015
September 2018	L2014_3	    8597  0.966
September 2018	L2017	    73	  0.008
September 2018	NYSPCMH	    74	  0.008
December  2018	L2011_12	0	  0
December  2018	L2011_3	    0	  0
December  2018	L2014_12	134	  0.015
December  2018	L2014_3	    7930  0.906
December  2018	L2017	    73	  0.008
December  2018	NYSPCMH	    613	  0.07
March     2019	L2011_12	0	  0
March     2019	L2011_3	    0	  0
March     2019	L2014_12	139	  0.015
March     2019	L2014_3  	7446  0.817
March     2019	L2017	    77	  0.008
March     2019	NYSPCMH	    1454  0.159
;

data data1(drop = month year);
  set  data  ;
   date = input (catx(' ','1',month,year),anydtdte18.);
   format date monyy7.; 
format precent percent10.;
run;

thank you for helping!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 3603 views
  • 0 likes
  • 2 in conversation