Date: Tue, 31 Jan 2006 17:02:07 -0600
Reply-To: Jiann-Shiun Huang <Jiann-Shiun.Huang@AMERUS.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Jiann-Shiun Huang <Jiann-Shiun.Huang@AMERUS.COM>
Subject: Re: How to put obs that are in different rows into one row
Content-Type: text/plain; charset=US-ASCII
Toby:
Let me assume that there are at most 3 subjects per organization. If
not, you will need to modify to make it work. Here is the code and the
output follows it. Let me know if it does not work.
data temp;
input obid sbid m1 m2 m3 m4 m5;
datalines;
2 1 55 66 77 44 55
2 2 54 64 22 65 26
4 3 56 77 34 73 84
4 4 54 23 54 11 65
5 5 34 73 26 73 74
5 6 34 55 23 55 45
5 7 34 36 34 24 74
;
run;
data temp2(drop=i count sbid m1-m5);
retain obid m11-m15 m21-m25 m31-m35;
set temp;
by obid sbid;
array m(5) m1-m5;
array A(3,5) m11-m15 m21-m25 m31-m35;
if first.obid then count=1;
else count+1;
do i=1 to 5;
A(count,i)=m(i);
end;
if last.obid then output;
run;
proc print data=temp2;
title 'temp2 data set';
run;
***** Output *****
temp2 data set 07:40
Tuesday, January 31, 2006 131
Obs obid m11 m12 m13 m14 m15 m21 m22 m23 m24 m25 m31
m32 m33 m34 m35
1 2 55 66 77 44 55 54 64 22 65 26 .
. . . .
2 4 56 77 34 73 84 54 23 54 11 65 .
. . . .
3 5 34 73 26 73 74 34 55 23 55 45 34
36 34 24 74
J S Huang
1-515-557-3987
fax 1-515-557-2422
>>> <toby989@HOTPOP.COM> 1/31/2006 3:35:10 PM >>>
Hi All
My data looks like:
organizatonid subjectid m1 m2 m3 m4 m5
2 1 55 66 77 44 55
2 2 54 64 22 65 26
4 3 56 77 34 73 84
4 4 54 23 54 11 65
5 5 34 73 26 73 74
5 6 34 55 23 55 45
5 7 34 36 34 24 74
And I want
oid m11 m12 m13 m14 m15 m21 m22 m23 m24 m25 m31 m32 m33 m34 m35
2 55 66 77 44 55 54 64 22 65 26
4 56 77 34 73 84 54 23 54 11 65
5 34 73 26 73 74 34 55 23 55 45 34 36 34 24 74
The dataset is huge. There are more than 5 measurements illustrated
above, there are more than 3 subjects per organization, and there are
more than these 3 organizations.
I was thinking of using set or merge in a datastep together with a do
(it.) statement but then I cant access the counter to create variable
names. I am also not expereinced enought to know how to access
specific
rows with their obs number.
Thanks for your hint.
Toby