SAS ODS 文本边距比 PROC REPORT 中的表格宽

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

我正在修改我们的资助者提供的现有 SAS 程序,以自动创建 RTF 报告表,其样式与我们过去的报告外观相匹配。我遇到两个问题:

  1. ODS 文本的边距比表格本身更宽,导致粘贴到文档时出现问题
  2. 现有报告没有水平网格线,但有垂直网格线,应为彩色 bed3d7

我花了几个小时试图解决这两个问题。 我正在使用 Enterprise Guide 8.2 Update 5。这是代码(请注意,因为我有几个类似的表,所以我设置了一个宏以便于格式化)


%let out = ;

data demo1;
    length characteristic $30 clevel $50;
    input characteristic $ clevel $ cfrequency crowpercent Lower_CI Upper_CI;
    datalines;
Race/Ethnicity Asian 7 3.5 0.9 6.2
Race/Ethnicity Black 25 12.3 7.6 16.9
Race/Ethnicity Latinx 92 41.2 34.5 47.8
Race/Ethnicity NHPI 5 0.7 0.0 2.0
Race/Ethnicity White 100 37.9 31.5 44.3
Race/Ethnicity Multiple 9 4.5 1.5 7.5
Age 18-24 5 1.9 0.0 3.7
Age 25-34 28 11.6 7.3 15.8
Age 35-44 41 19.3 13.8 24.8
Age 45-54 58 26.2 20.1 32.2
Age >=55 103 41.1 34.6 47.7
;
run;

data demo2 (drop=Lower_CI Upper_CI);
set demo1;
CI=catx('-', put(Lower_CI, 4.1), put(Upper_CI, 4.1));
run;

%macro outtable1 (tableno=, columnwidth=, headerheight=, cellheight=, clevelwidth=, cfrequencywidth=, 
                crowwidth=, CIwidth=, spanhead=);

goptions device=emf;
title;
options nodate orientation=portrait nonumber;
ods escapechar='^';
ods rtf file = "&out\&tableno..rtf";

proc report split='*' nowindows data=&tableno nowindows style(column)={asis=on}
style(report)={LEFTMARGIN=0.5in font_face="arial" font_size=14pt color=black rules=none BACKGROUND=_undef_ frame=hsides
               background=cxe8efef borderwidth = .01in posttext=" "}
style(column)={just=left font_face="arial" cellspacing = 0 font_size=12pt  
               cellwidth=&columnwidth rules=none background=white}
style(header)={just=left vjust=center font_face="arial" font_weight=bold font_size=12pt color=white
               cellheight=&headerheight font_size=12pt rules=rows 
               frame=hsides background=cx007077 paddingleft=0.15in}
style(lines) ={background=cxf0f5f5};

column ("%bquote(&spanhead)" (characteristic clevel cfrequency crowpercent CI));

define characteristic / order noprint order=data width=60 flow; 
define clevel         / display '' CENTER order=internal
                        style(column)={cellwidth=&clevelwidth just=left paddingleft=0.2in}
                        style(header)={cellheight=&cellheight cellwidth=&clevelwidth just=left background=cxbed3d7 color=black};
define cfrequency     / 'Number^{super a}' CENTER 
                        style(column)={cellwidth=&cfrequencywidth just=CENTER}
                        style(header)={cellheight=&cellheight cellwidth=&cfrequencywidth just=CENTER background=cxbed3d7 color=black};
define crowpercent    /'Percentage^{super b}' CENTER 
                        style(column)={cellwidth=&crowwidth just=CENTER}
                        style(header)={cellheight=&cellheight cellwidth=&crowwidth just=CENTER background=cxbed3d7 color=black};
define CI             / '95% CI^{super c}' CENTER WIDTH=25
                        style(column)={cellwidth=&CIwidth just=CENTER}
                        style(header)={cellheight=&cellheight cellwidth=&CIwidth just=CENTER background=cxbed3d7 color=black};
compute before characteristic / style = [font_weight=bold font_size=12pt font_face="arial" font_style=italic paddingleft=0.2in]; 
line @1 characteristic $195. ; 
endcomp;
COMPUTE clevel;
IF clevel= 'Total' THEN CALL DEFINE(_ROW_, "style", "STYLE=[font_weight=bold background=cxbed3d7]");
ENDCOMP;
run;

%mend;

%include "&path.\outtable1.sas";

%outtable1(tableno=demo2, columnwidth=0.6in, headerheight=0.3in, cellheight=0.3in, clevelwidth=3.2in, 
            cfrequencywidth=1.3in, crowwidth=1.3in, CIwidth=1.3in, spanhead=%str(3.1. Demographics, 2022));

ODS TEXT='^S={LEFTMARGIN=0.5in RIGHTMARGIN=0.5in fontsize=9pt font_face="arial"}';
ODS TEXT='^S={LEFTMARGIN=0.5in RIGHTMARGIN=0.5in fontsize=9pt font_face="arial"}Abbreviations: CI, confidence interval; [footnotes only].';
ODS TEXT='^S={LEFTMARGIN=0.5in RIGHTMARGIN=0.5in fontsize=9pt font_face="arial"}^{style[font_style=italic]Note}. Numbers might not add to total because of “don’t know”
 and skipped (missing) responses. Percentages might not sum to 100 because of rounding. Estimates with a denominator sample size of <30, an absolute CI width ^{Unicode 2265}30, estimates with an absolute CI width
 between 5 and 30 and a relative CI width >130%, and estimates of 0% or 100% are marked with an asterisk (*) and should be interpreted with caution.' ;
ODS TEXT='^S={LEFTMARGIN=0.5in RIGHTMARGIN=0.5in fontsize=9pt font_face="arial"}^{super a} Numbers are unweighted.';
ODS TEXT='^S={LEFTMARGIN=0.5in RIGHTMARGIN=0.5in fontsize=9pt font_face="arial"}^{super b} Percentages are weighted percentages.';
ODS TEXT='^S={LEFTMARGIN=0.5in RIGHTMARGIN=0.5in fontsize=9pt font_face="arial"}^{super c} CIs incorporate weighted percentages.';
ODS TEXT='^S={LEFTMARGIN=0.5in RIGHTMARGIN=0.5in fontsize=9pt font_face="arial"}^{super d} Hispanics or Latinos can be of any race. Persons are classified in only one
race/ethnicity category.';

照片示例表格显示了如果选择整个表格,脚注(使用 ODS 文本创建)的页边距如何比表格更宽。

这是一个相对简单的表,是我正在更新的 20 多个表之一。 任何帮助将不胜感激。

sas rtf ods proc-report
1个回答
0
投票

文档中所述:

UserText 样式元素控制使用 TEXT= 语句指定的文本。

相关的 style 属性

width
(别名
cellwidth
outputwidth
)。您还应该将输出放在页面的中心,就像对表格所做的那样。两者都可以通过使用
PROC TEMPLATE
修改或创建样式来设置。我不确定您使用的是哪种样式,甚至不确定哪一种是默认(看起来它在 EG 中有所不同),但这段代码应该或多或少可以满足您的需要——在我的例子中,宽度为 90%两个元素都很好地对齐:

ods path work.template(update) sashelp.tmplmst;
proc template;
   define style styles.myrtf;
      parent=styles.rtf;
      style usertext from usertext / just=c width=90%;
   end;
run;

然后,您必须在

ODS RTF
中调用此样式,并将
ODS TEXT
的实际内容左对齐(仅显示相关部分):

ods rtf style=myrtf file=...;
/* [.. PROC REPORT ..] */

ods text='^S={just=l ...}';
/* [.. more ODS TEXT ..] */
ods rtf close;
© www.soinside.com 2019 - 2024. All rights reserved.