仅在proc报告中获取特定的组换行符

问题描述 投票:0回答:3

我正在尝试使用proc格式来格式化表格,但无法弄清楚如何仅为数据中的特定组指定换行符。

“已输出”

想要

“想要输出”

当前是我的数据结构:

Data Structure

这里是我一直试图找出的代码...

title "Table 1";
options orientation = landscape nonumber nodate leftmargin=0.05in rightmargin=0.05in;
ods noproctitle noresults escapechar='^';
ods rtf  file = "path";

 proc report data= work.appendix_a1  nowd spanrows 
    style(header)=[vjust=b font_face = Calibri fontsize=9pt font_weight=bold background=&blue. foreground=white borderrightcolor=black];
    /*List variables in order to select order of columns in table*/
    col ( m_type1
          ('^S={borderbottomcolor=&blue. vjust=b borderbottomwidth=0.02 }Table'('^S={borderbottomcolor=&blue. vjust=b borderbottomwidth=0.02 }Characteristics' m_char_desc)) 
          ('^S={cellheight=0.20in}CY 2016' 
          ('^S={borderbottomcolor=&blue. borderbottomwidth=0.02 cellheight=0.18in}' count_16) 
          ('^S={borderbottomcolor=&blue. borderbottomwidth=0.02 cellheight=0.18in}' percentage_16))
          ('^S={cellheight=0.20in}CY2017' 
          ('^S={borderbottomcolor=&blue. borderbottomwidth=0.02 cellheight=0.18in}' count_17)
          ('^S={borderbottomcolor=&blue. borderbottomwidth=0.02 cellheight=0.18in}' percentage_17))
          ('^S={cellheight=0.20in}CY2018' 
          ('^S={borderbottomcolor=&blue. borderbottomwidth=0.02 cellheight=0.18in}' count_18)
          ('^S={borderbottomcolor=&blue. borderbottomwidth=0.02 cellheight=0.18in}' percentage_18)));

define m_type1 /order=data group noprint;

        define m_char_desc / order=data display  style = [vjust=m just=center cellwidth=0.90in font_face='Times New Roman' fontsize=8pt]
                         '' style(header)=[vjust=t just=left cellheight=0.05in] ;
        define count_16      /display style = [vjust=m just=center  cellwidth=0.45in cellheight=0.05in font_face='Times New Roman' fontsize=9pt] 
                         'n' style(header)=[vjust=t just=center cellheight=0.18in];
        define percentage_16  /display style = [vjust=m just=center  cellwidth=0.45in cellheight=0.05in font_face='Times New Roman' fontsize=9pt] 
                         '%' style(header)=[vjust=t just=center cellheight=0.18in];
        define count_17 /display style = [vjust=m just=center  cellwidth=0.45in cellheight=0.05in font_face='Times New Roman' fontsize=9pt] 
                         'n' style(header)=[vjust=t just=center cellheight=0.18in];
        define percentage_17  /display style = [vjust=m just=center  cellwidth=0.45in cellheight=0.05in font_face='Times New Roman' fontsize=9pt] 
                         '%' style(header)=[vjust=t just=center cellheight=0.18in];
        define count_18      /display style = [vjust=m just=center  cellwidth=0.45in cellheight=0.05in font_face='Times New Roman' fontsize=9pt] 
                         'n' style(header)=[vjust=t just=center cellheight=0.18in];
        define percentage_18  /display style = [vjust=m just=center  cellwidth=0.45in cellheight=0.05in font_face='Times New Roman' fontsize=9pt] 
                         '%' style(header)=[vjust=t just=center cellheight=0.18in];


compute before m_type1/
style=Header{just=l fontweight=bold fontsize=8pt};
length brkline $100;
brkline = catx('',m_type1);
line brkline $varying100.;
endcomp;

run;

ods rtf close; 
sas report
3个回答
1
投票

这将修改其他答案以使用$ VARYING格式产生所需的结果。

SAS关于此主题的使用说明:http://support.sas.com/kb/37/763.html

proc report data=sashelp.cars;
  where type = 'Sedan' and drivetrain = 'All' and msrp < 30000; 
  title "All wheel Sedans under $30K";
  columns origin make model msrp;
  define origin / order noprint;

  compute before origin 
  / style = [
      fontweight=bold 
      background=lightgray 
      textalign=left 
      cellpadding=111pt
    ]
  ;
    length linetext $200.;
    linetext = origin;
    if origin='Asia' then l=0;
    else l=length(linetext);
    line linetext $varying200. l;
  endcomp;

  compute origin;    
    if not missing(origin) then
      hold_origin = origin;

    if hold_origin = 'Asia' then
      call define (_row_, 'style', 'style=[fontweight=bold background=VLIG fontstyle=italic]');

  endcomp;
run;

enter image description here


0
投票

我不知道这是否是您的问题,但是$ VARYING需要一个长度变量。

line brkline $varying100. LENGTHVARIABLE;

要删除TOTAL行,将长度变量设置为0;


0
投票

LINE语句

不管似乎限制LINE的'逻辑',您都不能有条件地发出行语句(因此以某种方式阻止了TOTAL摘要行)。

来自文档:

LINE Statement提供用于编写​​自定义摘要的PUT语句功能的子集。

限制:该语句仅在与报表中的位置关联的计算块中有效。


您不能在条件语句(IF-THEN,IF-THEN / ELSE和SELECT)中使用LINE语句,因为只有在PROC REPORT执行了计算块中的所有其他语句之后,才会执行LINE语句。

详细信息行格式

一旦您了解order变量仅具有该组中第一条报告行的值,您将看到必须跟踪该值。 这是一组具有多行的情况(您的TOTAL没有)

  • 临时变量可用于有条件地跟踪compute noprint变量在order块中的值。
  • call define (_row_, 'style', 'style=[ … ]');可用于有条件地修改报告明细行样式。

示例:

ods rtf file='report.rtf';
ods escapechar='^';

proc report data=sashelp.cars;
  where type = 'Sedan' and drivetrain = 'All' and msrp < 30000; 
  title "All wheel Sedans under $30K";
  columns origin make model msrp;
  define origin / order noprint;

  compute before origin 
  / style = [
      fontweight=bold 
      background=lightgray 
      textalign=left 
      cellpadding=111pt
    ]
  ;
    length linetext $200.;

    if origin='Asia'
      then linetext = ' ';
      else linetext = origin;

    line linetext $200.;
  endcomp;

  compute origin;    
    if not missing(origin) then
      hold_origin = origin;

    if hold_origin = 'Asia' then
      call define (_row_, 'style', 'style=[fontweight=bold background=VLIG fontstyle=italic]');

  endcomp;
run;
ods rtf close;

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.