首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >GCHART等价于Proc GPLOT一致

GCHART等价于Proc GPLOT一致
EN

Stack Overflow用户
提问于 2013-12-05 22:23:33
回答 1查看 421关注 0票数 0

是否有一种方法可以使多个条形图具有均匀的轴与程序图形?

在proc gplot中,我可以使用以下统一选项:

代码语言:javascript
复制
proc gplot data=test uniform;
  by state;
  plot var*date;
run;

这将为所有使用相同轴范围的by变量提供一组绘图。

这个选项不存在于proc proc还有其他办法吗?我不能仅仅定义一个固定的范围,因为我的数据会有所不同。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-12-06 16:32:35

谢谢大家的投入。由于proc本身似乎没有一个好的解决方案,所以我采用了一种宏方法手动设置轴。

本文为我所做的工作提供了基础:http://analytics.ncsu.edu/sesug/2012/BB-09.pdf

由于我在任何地方都找不到该程序的文本,只能在不可搜索的PDF文件中找到,所以我在这里输入了它。我的版本添加了一个额外的参数,可选择地将低值按下,以便为低端以下的数据标签留出空间(如果您正在制作列图,其标签位于正值和负值以下)。

代码语言:javascript
复制
%macro set_axis_minmaxincrement(ds=,
                                axisvar=,
                                axis_length = 51,
                                sa_min = 999999,
                                sa_max = -999999,
                                returned_min = axis_min,
                                returned_max = axis_max,
                                returned_increment = axis_increment,
                                force_zero = 0,
                                pad_bottom = 0
                                ) ;

%global &returned_min &returned_max &returned_increment;

/* Find the high and low values. Note: a data step was used versus a proc */
/* to allow the application of the option parameters, if specified. */
proc sort data=&ds out=sortlb(keep=&axisvar);
  by &axisvar;
  where &axisvar ne .;
run;
data axisdata(keep=low high);
  retain low 0;
  set sortlb end=eof;
  by &axisvar;
  if _n_=1 then low = &axisvar;
  if eof then do;
    high = &axisvar;
    if &sa_min ^= 999999 and &sa_min < low then low = &sa_min;
    if &sa_max ^= -999999 and &sa_max > high then high = &sa_max;
    %if &force_zero = 1 %then %do;
      if low > 0 then low = 0;
      else if high < 0 then high = 0;
    %end;
    %if &pad_bottom = 1 %then %do;
      if low < 0 then low = low-((high-low)*.06);
    %end;
    output;
  end;
run;

data axisdata;
  set axisdata;
  /* insure that high is greater than low */
  if high <= low then do;
    if abs(low) <= 1 then high = low + 1;
    else high = low+10;
  end;

/* Calculate the conversion unit to transform the standard range to */
/* include the actual range. This value is used to convert the standard */
/* to the actual increment for the actual range. */

  axisrange = high - low;
/* ranges of less than 1 */
  if axisrange <= 6 then do;
    check = 6;
    conversion_unit = .01;
    do until (axisrange > check);
      check = check/10;
      if axisrange <= check then conversion_unit = conversion_unit / 10;
    end;
  end;

/* Ranges of 1 or greater */
  else do;
    check = 60;
    conversion_unit = 1.0;
    do while (axisrange > check);
      check = check*10;
      conversion_unit = conversion_unit * 10;
    end;
  end;
/* standardize the range to lie between 6 to 60 */
    unit_range = axisrange/conversion_unit;
/* Set the increment based on the unitized range */
/* 'Long' axis, 8 - 12 increments */
    %if &axis_length >50 %then %do;
      if      unit_range < 12 then axisinc = 1   * conversion_unit;
      else if unit_range < 24 then axisinc = 2   * conversion_unit;
      else if unit_range < 30 then axisinc = 2.5 * conversion_unit;
      else                         axisinc = 5   * conversion_unit;
    %end;
/* Otherwise, 'short' axis, 4-6 increments */
    %else %do;
      if      unit_range < 12 then axisinc = 2   * conversion_unit;
      else if unit_range < 18 then axisinc = 3   * conversion_unit;
      else if unit_range < 24 then axisinc = 4   * conversion_unit;
      else if unit_range < 30 then axisinc = 5   * conversion_unit;
      else                         axisinc = 10  * conversion_unit;
    %end;

/*Round the min's value to match the increment; if the number is */
/* rounded up so that it becomes larger than the lowest data value, */
/* decrease the min by one increment. */
  axislow = round(low,axisinc);
  if axislow > low then axislow = axislow - axisinc;
/* Round the max; if the number is rounded down, */
/* increase the max by one increment. */
  axishigh = round(high, axisinc);
  if axishigh < high then axishigh = axishigh + axisinc;
/* put the values into the global macro variables */
  call symput("&returned_min",compress(put(axislow, best.)));
  call symput("&returned_max",compress(put(axishigh, best.)));
  call symput("&returned_increment",compress(put(axisinc, best.)));
run;
%mend set_axis_minmaxincrement;
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20412056

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档