1

我需要绘制直方图来比较两个系列。我有以下代码,但 proc gchart 不起作用。

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:

在此处输入图像描述

有人可以帮我更改 proc gchart 代码,或者您可以使用自己的方法来执行此操作吗?

4

1 回答 1

0

正如其他人提到的 - 您的测试数据不包含您尝试在 PROC GCHART 中调用的变量 GROUP 和 VALUE2。我认为为了匹配您的示例,您需要将日期分成月份和年份,以便在并排的栏中绘制年份。下面是一些 GCHART 代码,可创建类似于您的示例的直方图。您需要将响应变量更改为您要绘制的图表。

希望这可以帮助。

*** 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;
于 2014-10-09T14:59:01.127 回答