我在SAS有一张桌子,
Group1 Group2 type
1.1 1.4 value
0.5 0.4 value
5 6 percent
4 10 percent
我想把它分成四列,如下所示:
Group1_value Group1_percent Group2_value Group2_percent
1.1 5 1.4 6
0.5 4 0.4 10
答案 0 :(得分:0)
简便方法是PROC SQL
这会很快而且很脏。
data have;
input group_1 group_2 type $;
cards;
1.1 1.4 value
0.5 0.4 value
5 6 percent
4 10 percent
;
run;
proc sql;
create table g1v as
select distinct group_1 as group1_value
from have
where type = 'value'
order by group_1 desc
;
create table g1p as
select distinct group_1 as group1_percent
from have
where type = 'percent'
order by group_1 desc
;
create table g2v as
select distinct group_2 as group2_value
from have
where type = 'value'
order by group_2 desc
;
create table g2p as
select distinct group_2 as group2_percent
from have
where type = 'percent'
order by group_2
;
data final;
merge g1v g1p g2v g2p;
run;
其他方法是使用宏工具(但如果type
中只有两个值,则可能没有必要)。
答案 1 :(得分:0)
使用DATA Step重塑数据后,您可以使用Proc TRANPOSE
。
data have;
input
Group1 Group2 type $; datalines;
1.1 1.4 value
0.5 0.4 value
5 6 percent
4 10 percent
run;
* reshape data for Proc TRANSPOSE;
data forTranspose;
set have;
by type notsorted;
if first.type then seq = 1; else seq + 1;
name = 'Group1_' || type;
value = group1;
output;
name = 'Group2_' || type;
value = group2;
output;
run;
proc sort data=forTranspose;
by seq;
run;
proc transpose data=forTranspose out=want;
by seq;
id name;
var value;
run;