首页 > 解决方案 > 在 proc 报告中仅获取特定的组换行符

问题描述

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

有输出

想要输出

这是目前我的数据的结构方式:

数据结构

这是我一直试图弄清楚的代码......

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; 

标签: sasreport

解决方案


这会修改另一个答案以使用 $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;

在此处输入图像描述


推荐阅读