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 (November 2007, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Mon, 26 Nov 2007 13:00:14 -0500
Reply-To:     J Sabatier <plessthanpointohfive@GMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         J Sabatier <plessthanpointohfive@GMAIL.COM>
Subject:      Re: Adding rows based on value of another variable
Content-Type: text/plain; charset="us-ascii"

Hi, Mark and Jack,

Both those methods worked fantastically. Thanks so much!

Jen

-----Original Message----- From: Terjeson, Mark [mailto:Mterjeson@russell.com] Sent: Monday, November 26, 2007 11:01 AM To: CP Jen; SAS-L@LISTSERV.UGA.EDU Subject: RE: Adding rows based on value of another variable

Hi Jen,

This may be one approach:

* make sample data ; data sample; input ID age_group risk event length; cards; 1 0 0 0 54 1 0 0 1 107 1 0 1 0 21 1 1 0 0 183 ; run;

* spread to separate rows ; data result(drop=length); set sample; do length = length to 1 by -1; output; end; run;

Hope this is helpful.

Mark Terjeson Senior Programmer Analyst, IM&R Russell Investments

Russell Investments Global Leaders in Multi-Manager Investing

-----Original Message----- From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of CP Jen Sent: Monday, November 26, 2007 7:52 AM To: SAS-L@LISTSERV.UGA.EDU Subject: Adding rows based on value of another variable

So I have a dataset that has a length variable.

Here's an example:

ID age_group risk event length --------------------------------------- 1 0 0 0 54 1 0 0 1 107 1 0 1 0 21 1 1 0 0 183

Age_group, risk, and event have two levels (0,1). Length is the number of days spent in a single combination of age_group, risk, and event that existed for an individual. Note, it is not required for an individual to experience all possible combinations. This is a natural record.

I would like to expand this dataset so there is a row for every day. So, this person has a total of 365 days so I would like 365 rows, keeping the values of the other variables appropriately assigned (ie, that age_group stays 0 for 182 days and then is 1 for 183 days, etc).

Will I use SQL? I was hoping there was a way to index length and tell SAS to insert that many rows...

Help?

Thanks,

Jen


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