【发布时间】:2015-09-09 22:52:21
【问题描述】:
我正在尝试创建一个类似于本文中创建的报告表: http://www.lexjansen.com/wuss/2004/data_presentation/c_dp_creating_custom_tables_.pdf
但是,由于某种原因,表中的分类(即格式化)变量在每个子类别之后输出了额外的一行。
论文中使用的代码:
data _null_;
set Table_DS;
by entry;
file out print header=hdr linesleft=remain;
* --- Report Body;
if first.entry then put /@&COL1 entry entry.;
else if entry=3 then put @&COL1 +3 gender gender.;
else if entry=4 then put @&COL1 +3 race race.;
put @&COL2 statc statc.
@&COL3 p1
@&COL4 p2
@&COL5 p3;
* --- Footer;
*Note: Cutoff value depends on the number;
* of lines required for the footer;
if last or remain < 9 then link ftr;
return;
* ----- PUT HEADER;
hdr:
...Insert titles...
...Insert column headers...
return;
* ----- PUT FOOTER;
ftr:
...Insert footnotes...
...Begin a new page...
return;
run;
我的代码:
data _null_;
set Table_DS end=last;
by entry;
file print header=hdr linesleft=remain;
* --- Report Body;
if first.entry then put /@ &COL1 entry entry.;
if entry=1 then put @ &COL1 +3 lineno sex.;
if entry=2 then put @ &COL1 +3 lineno race.;
if entry=3 then put @ &COL1 +3 lineno ethnic.;
if entry=6 then put @ &COL1 +3 lineno creatcat.;
if entry=7 then put @ &COL1 +3 lineno admitdx.;
put @ &COL2 statc statc.
@ &COL3 p1
@ &COL4 p2
@ &COL5 p3;
if last or remain < 4 then link ftr;
return;
hdr:
put
@1 'Table 4: Demographic and Baseline Characteristics'
/@1 '(ITT analysis set)'
/@1 '________________________________________________________________________________________________'
/@1 'Subject Stratum: All Strata'
/@56 'Group A Group B Total'
/@56 '(N=294) (N=285) (N=579)'
/@1 '________________________________________________________________________________________________';
return;
ftr:
put
@1 '________________________________________________________________________________________________'
/@1 "Using &ds data set from &deldate";
return;
return;
run;
从我的代码中选择的输出:
Table 4: Demographic and Baseline Characteristics
(ITT analysis set)
________________________________________________________________________________________________
Subject Stratum: All Strata
Group A Group B Total
(N=294) (N=285) (N=579)
________________________________________________________________________________________________
Sex
N 294 285 579
Female
n (%) 78 ( 26.5%) 80 ( 28.1%) 158 ( 27.3%)
Race
N 293 280 573
White
n (%) 289 ( 98.6%) 277 ( 98.9%) 566 ( 98.8%)
Black or African American
n (%) 2 ( 0.7%) 0 (N/A) 2 ( 0.3%)
Asian
n (%) 1 ( 0.3%) 0 (N/A) 1 ( 0.2%)
American Indian/Alaskan Native
n (%) 0 (N/A) 1 ( 0.4%) 1 ( 0.2%)
Other
n (%) 1 ( 0.3%) 2 ( 0.7%) 3 ( 0.5%)
Ethnicity
N 293 281 574
Not Hispanic/Latino
n (%) 284 ( 96.9%) 266 ( 94.7%) 550 ( 95.8%)
Hispanic/Latino
n (%) 9 ( 3.1%) 15 ( 5.3%) 24 ( 4.2%)
Age (yrs)
N 294 285 579
Mean 61.5 62.1 61.8
SD 9.2 9.2 9.2
Median 61.0 61.0 61.0
Minimum 34.0 36.0 34.0
Maximum 81.0 85.0 85.0
BMI (kg/m^2)
N 290 280 570
Mean 28.8 28.9 28.9
SD 4.8 4.7 4.7
Median 28.0 28.4 28.2
Minimum 18.2 18.7 18.2
Maximum 46.5 48.2 48.2
我查看了整篇论文并比较了我们的代码,但我无法弄清楚为什么格式化的分类变量将统计数据按到下一行,而连续的统计数据在打印时没有任何额外的行。
这里是示例数据:
P1 lineno statc P2 P3 entry
294 -1 1 285 579 1
78 ( 26.5%) 1 7 80 ( 28.1%) 158 ( 27.3%) 1
293 -1 1 280 573 2
289 ( 98.6%) 1 7 277 ( 98.9%) 566 ( 98.8%) 2
2 ( 0.7%) 2 7 0 (N/A) 2 ( 0.3%) 2
1 ( 0.3%) 3 7 0 (N/A) 1 ( 0.2%) 2
0 (N/A) 4 7 1 ( 0.4%) 1 ( 0.2%) 2
1 ( 0.3%) 5 7 2 ( 0.7%) 3 ( 0.5%) 2
293 -1 1 281 574 3
284 ( 96.9%) 0 7 266 ( 94.7%) 550 ( 95.8%) 3
9 ( 3.1%) 1 7 15 ( 5.3%) 24 ( 4.2%) 3
294 . 1 285 579 4
61.5 . 2 62.1 61.8 4
9.2 . 3 9.2 9.2 4
61 . 4 61 61 4
34 . 5 36 34 4
81 . 6 85 85 4
290 . 1 280 570 5
28.8 . 2 28.9 28.9 5
4.8 . 3 4.7 4.7 5
28 . 4 28.4 28.2 5
18.2 . 5 18.7 18.2 5
46.5 . 6 48.2 48.2 5
【问题讨论】:
-
如果你在这个语句的末尾加上一个
@符号(以防止 put 语句以换行符结束)会发生什么:@ &COL5 p3 @;? -
顺便说一句:这是一种用于学习 SAS 报告基础知识的有趣方法,但就目前而言,我不会在生产中使用它。
PROC REPORT能够生成相同的表,或者足够接近,而定制工作要少得多,如果你确实需要一些定制的东西,你可以通过使用proc template表甚至只是将上面的宏宏化来做得比这更好. -
@RobertPenridge 似乎已经将“N”行向下移动了 1 行,因此所有 n(%) 也向下移动了 1 行。此外,除了最后一行“Maximum”之外,连续的 var 描述都消失了。我将继续使用指针,但我可能会听取 Joe 的建议并考虑使用 proc 报告。感谢您的帮助!
标签: sas