这是一个很好的例子,说明了使用多标签格式可以有所帮助.
首先,使用一个组变量将数据合并到一个数据集中,这样您就可以一次处理所有数据.(请注意,您发布的数据集步骤不起作用,因为您将教育定义为数字.)
data Group1;
input Subject_ID education $20.;
datalines;
1 LowerPrimary
2 Secondary
3 UpperPrimary
4 LowerPrimary
5 Secondary
6 Secondary
7 LowerPrimary
8 UpperPrimary
9 UpperPrimary
10 Secondary
;
data Group2;
input Subject_ID education $20.;
datalines;
1 LowerPrimary
2 Secondary
3 UpperPrimary
4 LowerPrimary
5 Secondary
6 Secondary
7 LowerPrimary
8 UpperPrimary
9 UpperPrimary
10 Secondary
11 LowerPrimary
12 UpperPrimary
;
data both;
set group1(in=in1) group2(in=in2);
if in1 then group='GROUP1';
else group='GROUP2';
run;
然后定义可生成所需类别的多标签格式.
proc format ;
value $education (multilabel notsorted)
'LowerPrimary' = 'LowerPrimary'
'UpperPrimary' = 'UpperPrimary'
'LowerPrimary','UpperPrimary' = 'Primary'
'Secondary' = 'Secondary'
'LowerPrimary','UpperPrimary','Secondary' = 'Group_Total'
;
run;
现在,我们可以使用支持多标签格式的过程(如PROC TABLATE)来生成报告.
proc tabulate data=both order=data ;
class group;
class education / mlf preloadfmt;
format education $education.;
table group,education;
run;
结果
---------------------------------------------------------------------------------------------
| | education |
| |----------------------------------------------------------------|
| |LowerPrimary|UpperPrimary| Primary | Secondary |Group_Total |
| |------------+------------+------------+------------+------------|
| | N | N | N | N | N |
|--------------------------+------------+------------+------------+------------+------------|
|group | | | | | |
|--------------------------| | | | | |
|GROUP1 | 3.00| 3.00| 6.00| 4.00| 10.00|
|--------------------------+------------+------------+------------+------------+------------|
|GROUP2 | 4.00| 4.00| 8.00| 4.00| 12.00|
---------------------------------------------------------------------------------------------