SAS转置的问题(全攻略)
(2014-03-14 01:12:27)id
1
1
2
2
想转换成:
id
1
1
2
2
请问怎么实现?
非常感谢
帮师弟处理数据时,遇到的一个问题。
首先看网络上的解决方案:
data
input Student $9. +1
datalines;
Capalleti 0545 1 94 91 87
Dubose 1252 2 51 65 91
Engles 1167 1 95 97 97
Grant 1230 2 63 75 80
Krupski 2527 2 80 76 71
Lundsford 4860 1 92 40 86
Mcbane 0674 1 75 78 72
;
run;
proc
run;
proc
run;
proc
run;
proc
run;
proc
id studentid;
idlabel student;
run;
proc
run;
data
infile datalines missover;
input Location & $10. Date date7.
Length1 Weight1 Length2 Weight2 Length3 Weight3
Length4 Weight4;
format date date7.;
datalines;
Cole Pond 2JUN95 31 .25 32 .3 32 .25 33 .3
Cole Pond 3JUL95 33 .32 34 .41 37 .48 32 .28
Cole Pond 4AUG95 29 .23 30 .25 34 .47 32 .3
Eagle Lake 2JUN95 32 .35 32 .25 33 .30
Eagle Lake 3JUL95 30 .20 36 .45
Eagle Lake 4AUG95 33 .30 33 .28 34 .42
;
proc
var length1-length4;
by location date;
run;
proc
run;
data
input Company $14. Date $ Time $ Price;
datalines;
Horizon Kites jun11 opening 29
Horizon Kites jun11 noon 27
Horizon Kites jun11 closing 27
Horizon Kites jun12 opening 27
Horizon Kites jun12 noon 28
Horizon Kites jun12 closing 30
SkyHi Kites jun11 opening 43
SkyHi Kites jun11 noon 43
SkyHi Kites jun11 closing 44
SkyHi Kites jun12 opening 44
SkyHi Kites jun12 noon 45
SkyHi Kites jun12 closing 45
;
proc
by company;
id date;
run;
proc
run;
data
input Program $ s1-s7;
datalines;
CONT 85 85 86 85 87 86 87
CONT 80 79 79 78 78 79 78
CONT 78 77 77 77 76 76 77
CONT 84 84 85 84 83 84 85
CONT 80 81 80 80 79 79 80
RI 79 79 79 80 80 78 80
RI 83 83 85 85 86 87 87
RI 81 83 82 82 83 83 82
RI 81 81 81 82 82 83 81
RI 80 81 82 82 82 84 86
WI 84 85 84 83 83 83 84
WI 74 75 75 76 75 76 76
WI 83 84 82 81 83 83 82
WI 86 87 87 87 87 87 86
WI 82 83 84 85 84 85 86
;
data
set weights;
array s{7} s1-s7;
Subject +
do Time
=
Strength = s{time};
output;
end;
drop s1-s7;
run;
proc
run;
proc
by program subject;
copy time strength;
var strength;
run;
proc
run;
师弟的例子:将
PROC IMPORT OUT=weights
RUN;
data split;
set weights;
array s{5} car1-car5;
Subject + 1;
do Time = 1 to 5;
car = s{time};
output;
end;
drop s1-s5;
run;
proc print data=split noobs;
run;
proc transpose data = split out = totsplit prefix = Str;
by
copy
var car;
run;
proc print data = totsplit;
run;
PROC EXPORT DATA=totsplit
RUN;
PROC EXPORT DATA=split
RUN;
1http://bbs.pinggu.org/thread-2943262-1-1.html
有数据集a如下:
mark
1077
1077
1077
1077
1119
1119
1119
20
20
想输出下面的结果:
1077
1119
20
求大大帮忙,万分感谢!
data a;
1077
1077
1077
1077
1119
1119
1119
20
20
;
run;
proc sort data=a;by mark;run;
proc transpose data=a out=b;
run;

加载中…