I need to draw a histogram to make comparison between two series. I have the following code, but the proc gchart is not working.
data test;
input date $ irate ppi savings income cpi;
datalines;
JUN1990 8.43 114.3 2.412 83.83 129.9
JUL1990 8.76 114.5 2.473 68.147 130.4
AUG1990 8.94 116.5 4.594 84.205 131.6
SEP1990 8.85 118.4 3.893 84.016 132.7
OCT1990 8.67 120.8 3.816 52.269 133.5
NOV1990 8.51 120.1 5.35 97.008 133.8
DEC1990 8.13 118.7 4.253 81.292 133.8
JAN1991 7.98 119 3.872 57.779 134.6
FEB1991 7.92 117.2 4.249 62.566 134.8
MAR1991 8.09 116.2 6.117 77.929 135
APR1991 8.31 116 3.69 92.044 135.2
MAY1991 8.22 116.5 3.798 59.509 135.6
JUN1991 8.02 116.3 1.812 59.549 136
JUL1991 7.68 116 2.951 49.197 136.2
;
run;
proc reg data=test;
model irate = ppi savings income cpi /p;
output out=b p=py;
run;
quit;
axis1 minor=none major=(h=1) label=none
order=(0 to 120000 by 10000) ;
axis2 major=(height=1) value=none
label=none offset=(5, 5)pct ;
axis3 label=none nobrackets ;
axis4 minor=none major=(h=1) label=none
order=(0 to 120000 by 60000) ;
axis5 minor=none major=(h=1) label=none
order=(0 to 120000 by 20000) ;
axis6 minor=none major=(h=1) label=none
order=(0 to 119000 by 17000) ;
pattern1 c=ligr ;
pattern2 c=gray ;
proc gchart data=test ;
title 'Too Many' ;
vbar group /
sumvar=value2 group=date
noframe nolegend
subgroup=group
raxis=axis1 maxis=axis2 gaxis=axis3
width=12 space=0 gspace=4
coutline=same ;
format date monname3. value2 comma10.0;
run ;
title 'Odd Tick Mark Intervals' ;
vbar group /
sumvar=value2 group=date
subgroup=group
noframe nolegend
raxis=axis6 maxis=axis2 gaxis=axis3
width=12 space=0 gspace=4
coutline=same ;
format date monname3. value2 comma10.0;
run ;
quit ;
I want to make the final graph like this:
Can someone help me to change the proc gchart code or you can use your own method to do this?
As someone else mentioned - your test data does not contain the variables GROUP and VALUE2 that you are trying to call in your PROC GCHART. I think to match your example, you will need to separate the date into month and year in order to chart year in side-by side bars. Below is some GCHART code that creates a histogram similar to your example. You will need to change the response variable to what you are trying to chart.
Hope this helps.
*** CREATE MONTH AND YEAR AS SEPARATE VARIABLES ***;
data test_fix;
set test;
*** FIRST CONVERT DATE FROM CHARACTER STRING TO NUMERIC SAS DATE VARIABLE ***;
date_sas=input(date, ANYDTDTE.);
*** USE SAS DATE VARIABLE TO GET MONTH AND YEAR AS NUMERIC VARIABLES ***;
month=month(date_sas);
year=year(date_sas);
run;
proc print data=test_fix;
format date_sas mmddyy10.;
run;
axis1 label=('MONTH') offset=(5,5);
axis2 label=none value=none;
axis3 label=(a=90 'PPI') ;
pattern1 v=solid color=greyc0; *** LIGHT GREY ***;
pattern2 v=solid color=grey40; *** DARY GREY ***;
proc gchart data=test_fix;
vbar year /
type=sum sumvar=ppi
group=month subgroup=year
discrete
space=0
gaxis=axis1 /* GROUP AXIS (X-AXIS) - MONTH */
maxis=axis2 /* MID POINT AXIS (X-AXIS) - YEAR */
raxis=axis3 /* RESPONSE AXIS (Y-AXIS) - PPI */
;
run;
quit;