【问题标题】:SAS Proc Report banded rows with skipped lineSAS Proc Report 带跳行的带状行
【发布时间】:2020-09-15 21:47:09
【问题描述】:

我正在使用 PROC REPORT 生成输出。我需要交替颜色的带状线,并且能够通过增加计数器变量并测试行号是奇数还是偶数来实现这一点,这可以按预期工作。我还使用计算块在每组订单变量之后添加一个空行。我希望空行的背景颜色也由计数器变量的值确定,但这似乎是不可能的。我不想在运行 PROC REPORT 之前将空白行添加到数据集,有没有解决方案。请在下面找到代码:

PROC REPORT DATA = sashelp.class NOWD SPLIT = "!" HEADLINE HEADSKIP MISSING ;
  COLUMN sex name ;
  DEFINE sex / ORDER ;
  ***this adds banding to the rows and works as expected ***;
  COMPUTE name;
    count+1;
    IF MOD(count, 2) gt 0 THEN DO;
      CALL DEFINE(_ROW_,'STYLE','style=[background=red]');
    END;
    ELSE DO;
      CALL DEFINE(_ROW_,'STYLE','style=[background=green]');
    END;
  ENDCOMP;
  ***section adds a blank line and I can control the background colour but I can t assign this colour based on the value of the count variable ***; 
  COMPUTE AFTER sex  /  style=[background=blue] ; 
    LINE " "    ;
  ENDCOMP;
RUN;

【问题讨论】:

  • 您想要的基于计数的背景颜色有哪些示例? IE。数 0-10 蓝色,11-30 橙色,31-75 紫色?
  • 感谢您的回复。我想要交替的行带,所以奇数行一种颜色,偶数行另一种颜色。这在我提供的示例代码中有所说明,它确实有效,问题是如何动态设置插入的空白行的颜色,我可以控制颜色但不能动态地这样做,即我不知道如何在第二个计算块中,我可以访问 count 变量并使用它的值来设置颜色。
  • 您正在使用哪个 ODS 目标(HTML、PDF、RTF、其他?)
  • 我正在写 PDF,但我认为无论是 PDF 还是 HTML 都一样?
  • 使用 HTML,您可以输出包装内容的原始 html,以强制 LINES 单元格具有背景(即,将内容嵌入文字
    中)。不幸的是,无法动态(以编程方式)设置由 COMPUTE AFTER LINE 语句创建的单元格样式。

标签: sas


【解决方案1】:

总是有老办法:

proc sort data = sashelp.class out = test;
  by sex;
run;

data test;
  set test;
  by sex;

  output;
  if last.sex then do;
    call missing(name);
    output;
  end;
run;

proc report data = test;
  column sex name ord;
  define sex /order order = data;
  define ord /noprint;

  compute name;
    count + 1;
    if mod(count, 2) then do;
      call define(_row_,'style','style=[background=green]');
    end;
    else do;
      call define(_row_,'style','style=[background=red]');
    end;
  endcomp;
run;

如果你可以通过修改选项来解决它,请分享你的技能。

【讨论】:

  • 感谢您的评论。我同意这种方法可行,但我真的在寻找一种无需在数据集中插入空白行即可解决问题的方法。如果我找到解决方案,我会在这里发布。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多