LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (October 2008, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Tue, 28 Oct 2008 19:46:11 -0400
Reply-To:   "Howard Schreier <hs AT dc-sug DOT org>" <schreier.junk.mail@GMAIL.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   "Howard Schreier <hs AT dc-sug DOT org>" <schreier.junk.mail@GMAIL.COM>
Subject:   Re: concatenate strings/dates in groups

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.


Back to: Top of message | Previous page | Main SAS-L page