sas数据、格式和;输出额外换行符的put语句
我正在尝试创建一个类似于本文中创建的报告表: 然而,出于某种原因,表中的分类(即格式化)变量在每个子类别后输出一行额外的内容 文件中使用的代码:sas数据、格式和;输出额外换行符的put语句,sas,Sas,我正在尝试创建一个类似于本文中创建的报告表: 然而,出于某种原因,表中的分类(即格式化)变量在每个子类别后输出一行额外的内容 文件中使用的代码: 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 th
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;
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.;
我看了整篇文章并比较了我们的代码,但我不明白为什么格式化的分类变量将统计数据标记到下一行,而连续统计数据打印时中间没有任何额外的行
以下是示例数据:
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
您的问题是通过分析上述代码中的差异发现的。从经验上来说,这有点困难(因为您没有提供样本数据,所以我不能100%确定数据集是什么样子),但是: 您的代码:
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.;
论文中的原始代码:
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;
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.;
在第一行,first.entry
,它放入条目(Sex
等),然后处理另一行,如果entry=1,则放入@&COL1+3行no Sex
我假设这些行上可能缺少lineno
(或者是0或其他由sex.
格式设置为缺少的内容)
在最初的文章中,这从未对
行执行过。entry
行,因为它位于else
块中。如果在该语句末尾放置@
符号(防止put语句以新行字符结束):@&COL5 p3代码>?作为旁白:这是一种学习SAS中报告基础知识的有趣方法,但就目前情况而言,我不会在生产中使用它PROC REPORT
能够生成相同的表,或者足够接近,只需要很少的自定义工作,如果您确实需要一些自定义内容,您可以通过使用PROC template
表,甚至只是对上面的内容进行宏化来做得更好。@RobertPenridge它似乎已经将“N”行下移了一行,因此所有的N(%)也向下移动1行。此外,除了“最大值”的最后一行之外,连续变量描述都消失了。我将继续使用指针,但我可能会接受Joe的建议,并考虑使用proc report。谢谢你的帮助!不幸的是,将适当的“else-if”添加到lineno语句会产生与仅使用“if”相同的结果。