|
On Tue, 28 Oct 2008 08:18:27 -0700, haoyugu@GMAIL.COM wrote:
>Hi Group,
>Anyone know how to concatenate all the distinct 'dates' in groups of id
>+sampleid to form the new variable "dates"?
>
>data test;
> input id sampleid date date9. ;
> cards;
> 1 1 30Sep2008
> 1 1 11Oct2008
> 1 1 13Oct2008
> 1 2 29Sep2008
> 1 2 09Oct2008
> 1 2 10Oct2008
> ;
>
>The result I want is:
> id sampleid date dates
> 1 1 17805 17805,17816,17818
> 1 1 17816 17805,17816,17818
> 1 1 17818 17805,17816,17818
> 1 2 17804 17804,17814,17815
> 1 2 17814 17804,17814,17815
> 1 2 17815 17804,17814,17815
>
>The numbers in 'date' and 'dates' corresponds to date in "test".
>Thanks a lot,
>
>Haley
I would use something along these lines:
data want;
set test(in = firstpass) test;
by id sampleid;
length dates $ 100;
retain dates;
if first.sampleid then call missing(dates);
if firstpass then dates = catx(',' , dates, date);
else output;
run;
The limitation is that you have to hard-code an upper bound for the length
of DATES.
|