LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous (more recent) messageNext (less recent) messagePrevious (more recent) in topicNext (less recent) in topicPrevious (more recent) by same authorNext (less recent) by same authorPrevious page (January 2005, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 20 Jan 2005 08:52:51 -0800
Reply-To:     Dennis Diskin <diskin@SNET.NET>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Dennis Diskin <diskin@SNET.NET>
Subject:      Re: combining multiple records into one observation
Comments: To: Joan A <joanab1970@YAHOO.COM>
In-Reply-To:  <20050120163453.77338.qmail@web30906.mail.mud.yahoo.com>
Content-Type: text/plain; charset=us-ascii

Joan,

Here's a straightforward datastep solution which assumes that your flags are character strinfs as shown. If they were instead, numeric values, it would be simpler.

%let nflags=25; data new(drop=_:); set input (rename=(flag1-flag&nflags=_flag1-_flag&nflags)); by id year; array _flag(&nflags); array flag(&nflags) $ 5; retain flag1-flag&nflags; if first.year then do _i = 1 to &nflags; flag(_i) = _flag(_i); end; else do _i = 1 to &nflags; if _flag(_i) eq 'true' then flag(_i) = 'true'; end; if last.year; run;

HTH, Dennis Diskin

Joan A <joanab1970@YAHOO.COM> wrote: Hello, I am seeking help combining multiple records into one unique observation (for each id and each year). For example, I have.

Id Year flag1 flag2 ......flag25 0022233 2000 true true true 0022233 2000 false false true 0022233 2000 true false true 0022233 2001 true false false 0022233 2003 false false true 0022233 2004 true false true 0022233 2004 false true false

I need to create a new record combining all the flags for "each id for each year." If any flag was marked "true" for a given id in a given year, then I need to mark it as true in the new record.

Desired output: Id Year flag1 flag2 ......flag30 0022233 2000 true true true 0022233 2001 true false false 0022233 2003 false false true 0022233 2004 true true true

Your assistance is greatly appreciated!! Joan

--------------------------------- Do you Yahoo!? Yahoo! Search presents - Jib Jab's 'Second Term'


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