我试图以纯文本格式化proc report
的输出。我有一个变量,我通过它对观察结果进行分组,并且跨越两行。这会导致明显的换行并分离分组的观察结果。有没有任何巧妙的方法来解决这个问题?
以下最小示例说明了该问题。
编辑:该计划最好也适用于某些科目的一项观察。
程序:
* Toy data ;
data mydata;
length subj $ 20;
input subj $ val val2;
datalines;
ID001|M 7.1 5.2
ID001|M 7.1 4.9
ID001|M 7.1 5.3
ID001|M 7.1 5.6
ID001|M 7.1 5.7
ID020|F 7.1 3.2
ID020|F 7.3 2.9
ID020|F 7.2 0.9
ID300|M 7.2 1.2
ID300|M 7.2 1.8
;
run;
* Create report ;
ods listing;
proc report data=mydata headline headskip split='|';
column(subj val val2);
define subj / order flow 'Subject ID|Sex';
define val / 'Value 1';
define val2 / 'Value 2';
break after subj / skip;
run;
ods _all_ close;
输出:
Subject ID
Sex Value 1 Value 2
------------------------------------------
ID001 7.1 5.2
M
7.1 4.9
7.1 5.3
7.1 5.6
7.1 5.7
ID020 7.1 3.2
F
7.3 2.9
7.2 0.9
ID300 7.2 1.2
M
7.2 1.8
期望的输出:
Subject ID
Sex Value 1 Value 2
------------------------------------------
ID001 7.1 5.2
M 7.1 4.9
7.1 5.3
7.1 5.6
7.1 5.7
ID020 7.1 3.2
F 7.3 2.9
7.2 0.9
ID300 7.2 1.2
M 7.2 1.8
替代期望的输出:
Subject ID
Sex Value 1 Value 2
------------------------------------------
ID001
M 7.1 5.2
7.1 4.9
7.1 5.3
7.1 5.6
7.1 5.7
ID020
F 7.1 3.2
7.3 2.9
7.2 0.9
ID300
M 7.2 1.2
7.2 1.8
或类似的东西,可以清楚地在视觉上区分群体。
答案 0 :(得分:3)
我缩进了性别,但你可以删除它。确保每个受试者有2个或更多个人。
data mydata;
length subj $ 20;
input subj $ val val2;
length sex $3;
sex = ' '||scan(subj,-1);
subj = scan(subj,1);
datalines;
ID001|M 7.1 5.2
ID001|M 7.1 4.9
ID001|M 7.1 5.3
ID001|M 7.1 5.6
ID001|M 7.1 5.7
ID020|F 7.1 3.2
ID020|F 7.3 2.9
ID020|F 7.2 0.9
ID300|M 7.2 1.2
ID300|M 7.2 1.8
;;;;
run;
proc print;
run;
* Create report ;
*ods listing;
proc report data=mydata headline headskip split='|' list
/* showall*/
;
column(subj sex stub val val2);
define subj / order noprint;
define sex / order noprint;
define stub / computed width=10 'Subject' ' Gender';
define val / 'Value 1';
define val2 / 'Value 2';
break after subj / skip;
compute before subj;
xsubj = subj;
endcomp;
compute before sex;
j = 0;
xsex = sex;
endcomp;
compute stub / char length=20;
j + 1;
if j eq 1 then stub = xsubj;
else if j eq 2 then stub = xsex;
else stub = ' ';
endcomp;
run;
答案 1 :(得分:0)
如果需要,只需加上一个,确保所有受试者都有两个或更多个。
data addonemaybe / view=addonemaybe;
set mydata;
by subj;
output;
if first.subj and last.subj then do;
call missing(of val:);
output;
end;
run;