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 (May 2000, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Mon, 1 May 2000 23:23:11 GMT
Reply-To:     sashole@mediaone.net
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Paul Dorfman <paul_dorfman@HOTMAIL.COM>
Subject:      Re: Reshaping data?
Comments: To: bja-bob@MINDSPRING.COM
Content-Type: text/plain; format=flowed

Bradley,

Judging from your output, you just have to repeat the record 30 times:

data vert (keep=id day var:); set hor; do day=1 to 30; output; end; run;

Note that there is a slight inconsistency between your input as shown and the desired output: There is no dependency on the way the days are valued. No matter whether the boolean variable day is set to 1 or 0, the record winds up in the output. In the case you might want to output only records corresponding to the non-zero days, the code above should be somewhat amended:

data vert (keep=id day var:); array d(*) day1-day30; set hor; do day=1 to 30; if d(day) then output; end; run;

Kind regards, ===================== Paul M. Dorfman Jacksonville, Fl =====================

>From: "Bradley J. Anderson" <bja-bob@MINDSPRING.COM> >Reply-To: "Bradley J. Anderson" <bja-bob@MINDSPRING.COM> >To: SAS-L@LISTSERV.UGA.EDU >Subject: Reshaping data? >Date: Mon, 1 May 2000 18:26:02 -0500 > >I need to "reshape" a SAS data set and am having problems figuring out how >to do this efficiently. Assume the original data are as follows: > >ID day1 day2 day3 ..... day 30, var1 var2 var3 ... var30 >1 1 0 1 1 10 12 9 23 > 2 1 1 0 1 9 11 7 >21 >3 0 0 1 0 11 10 9 22 >. >. >. >N > >I want to reshape and expand the data so that there will be 30 observations >for each of the cases in the original data set. The reshaped data set will >have N*30 observations. Such as: > >ID Day Var1 Var2 ... >1 1 10 12 >1 2 10 12 >1 3 10 12 >. . >1 30 10 12 >. >2 1 9 11 >2 2 9 11 >. . . . >2 30 9 11 >. >N 1 ..... >N 2 ..... > >In short, I want to create 30 days worth of observations (days will become >the unit of analysis) for each of the orginal cases. A colleague using >Stata has been using a combination of a "reshape" command and an "expand" >command to reshape such data appropriately. I'm trying to convert what my >colleague has done into a SAS program. It's has to be pretty easy, but I'm >stumbling on this one. I'd be most appreciative if anyone can offer an >efficient solution. Thanks in advance.

________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com


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