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 (February 2008, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 22 Feb 2008 13:50:37 -0500
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: Another way of doing this?

On Fri, 22 Feb 2008 10:28:48 -0500, Gerhard Hellriegel <gerhard.hellriegel@T-ONLINE.DE> wrote:

>I assume, there is a VERY elegant SQL solution.

Since SQL does not like this kind of "wide" data structure, I would assume the opposite.

>I'd do it like that: > >DATA UniqueReason; > LENGTH Reason $12; > SET DisCont; > array r(*) r1-r5; > do i=1 to dim(r); > if r(i) then reason="Reason "!!put(i,2.); > end; >RUN; > >Gerhard

Or:

DATA UniqueReason; LENGTH Reason $12; SET DisCont; Reason = catx(' ','Reason',index(cats(of r1-r5),'1') ); RUN;

The formula first turns the five variables into a series of dots and 1's, then finds the first 1 and concatenates it to the literal "Reason".

No array, no loop, no "wallpaper".

> > > > >On Fri, 22 Feb 2008 07:13:27 -0800, Franz <franz_cl2003@YAHOO.FR> wrote: > >>Dear All, >> >>I have the following situation where Patient >>discontinued a study due to five possible reasons R1 >>through R5. I would like to created one new variable >>REASON that will explicitly hold the description of >>that reason ("Reason 1", "Reason 2", "Reason 3", or >>"Reason 4", or "Reason 5"). >> >>DATA DisCont; >>INPUT Pat R1 R2 R3 R4 R5; >>CARDS; >>01 1 . . . . >>02 . 1 . . . >>03 . . 1 . . >>04 . . . 1 . >>05 . . . 1 . >>; >> >>DATA UniqueReason; >> LENGTH Reason $12; >> SET DisCont; >> IF R1 = 1 THEN Reason = "Reason 1"; >> ELSE IF R2 = 1 THEN Reason = "Reason 2"; >> ELSE IF R3 = 1 THEN Reason = "Reason 3"; >> ELSE IF R4 = 1 THEN Reason = "Reason 4"; >> ELSE IF R5 = 1 THEN Reason = "Reason 5"; >>RUN; >> >>A more elegant way of achieving this? >> >>Thank you very much for your help. >>Kind regards, >>Franz. >> >> >> >> >> >___________________________________________________________________________ >_________ >>Looking for last minute shopping deals? >>Find them fast with Yahoo! Search. >http://tools.search.yahoo.com/newsearch/category.php?category=shopping


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