|
I often use a lag to do something like this:
data test_docs;
set doc_cnt;
by fln;
/* create 7 NEW LAG QUES */
ARRAY X(*) date2 - date8;
date2 =LAG1(date);
date3 =LAG2(date);
date4 =LAG3(date);
date5 =LAG4(date);
date6 =LAG5(date);
date7 =LAG6(date);
date8 =LAG7(date);
/* reset COUNT when BY-group changes */
IF FIRST.fln THEN COUNT=1;
/* Reset the appropriate number of elements for
each lag queue. Once for LAG1, twice for LAG2,
and three times for LAG3... This stops 'bleed-over'
of previous BY-group into the current BY-group. */
DO i = COUNT TO DIM(x);
X(i)=.;
END;
count + 1;
;
You can then create the last column using compress:
Compress(var1,...,varn);
Run;
Then selcet the last row that has that id:
data doc_right;
set test_docs;
by fln;
if last.fln then output;
run;
Others might have better solutions, but this one is transparent and it
is easy to debug if it fails.
HTH.
Andrew
-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Yun
Bai
Sent: Monday, November 13, 2006 2:49 PM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Help, how can I combine specific cells together?
Hi, All
I have a table looks like:
ID Site Date Value
--------------------------
|001 | aa | aaa | a1 |
--------------------------
|001 | aa | aaa | a2 |
--------------------------
|001 | aa | aaa | a3 |
--------------------------
|002 | bb | bbb | b1 |
--------------------------
|002 | bb | bbb | b2 |
--------------------------
|003 | cc | ccc | c1 |
--------------------------
|004 | dd | ddd | d1 |
--------------------------
|004 | dd | ddd | d2 |
--------------------------
I want to generate a new table to combine the last column together for
the same ID, site and date. Like this:
ID Site Date Value
----------------------------------
|001 | aa | aaa | a1; a2; a3 |
----------------------------------
|002 | bb | bbb | b1; b2 |
----------------------------------
|003 | cc | ccc | c1 |
----------------------------------
|004 | dd | ddd | d1; d2 |
----------------------------------
How can I that? Thank you very much!
|