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 (March 2009, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Mon, 23 Mar 2009 12:24:17 -0700
Reply-To:     "Schwarz, Barry A" <>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "Schwarz, Barry A" <>
Subject:      Re: recalculate variables - retain?
Comments: To: pbpbta@GOOGLEMAIL.COM
In-Reply-To:  <>
Content-Type: text/plain; charset="us-ascii"

Does your fist sentence mean that instead of being sorted by cicleid they should be sorted by startdate? Sorting by id/cycle/startdate will swap the two observations for cycle 3.

But your second sentence is confusing. Since cycle 5 and 6 have only one observation each, there is nothing to sort within each cycle. Did you mean that these two observations should be swapped because cycle 6 occurred first? If so, then sorting by id/startdate will swap the two observations for cycle 3 and the one observation each for cycle 5 and 6. But, if a cycle with multiple observations has dates far enough apart, there might be intervening cycles between these observations.

In either case, after sorting you would have to reconstruct the cycle and cycleid variables.

Change the first observation for cycle 3 to 15 Oct and tell us what the output should be.

If you can guarantee that the cycles never overlap then

Sort by id and startdate

Loop through observations If first observation for this id Set new_cycle to 0 Set saved_cycle to missing Endif If cycle different from saved_cycle Increment new_cycle Set new_cycleid to 0 Save cycle in saved_cycle Endif Set cycle to new_cycle Increment new_cycleid Set cycleid to new_cycleid Write observation to data set Endloop

-----Original Message----- From: Pete Miller Sent: Monday, March 23, 2009 11:26 AM To: SAS-L@LISTSERV.UGA.EDU Subject: recalculate variables - retain?

Dear list members,

i've got following problem with a dataset that looks like:

data have; input id cycle cycleid startdate enddate; cards; 1 1 1 1JUL2005 31JUL2005 1 2 1 1AUG2005 31AUG2005 1 3 1 15SEP2005 30SEP2005 1 3 2 1SEP2005 14SEP2005 1 4 1 1OCT2005 30OCT2005 1 5 1 1DEC2005 31DEC2005 1 6 1 1NOV2005 30NOV2005 ; run;

My problem is, that for cycle= 3 the subcycles or cycleid's are correct, bur they should be in order of the date variables. This should also be done for the cycles 5 and 6;

so that the dataset should look like: data need; input id cycle cycleid startdate enddate; cards; 1 1 1 1JUL2005 31JUL2005 1 2 1 1AUG2005 31AUG2005

1 3 1 1SEP2005 14SEP2005 1 3 2 15SEP2005 30SEP2005

1 4 1 1OCT2005 30OCT2005

1 5 1 1NOV2005 30NOV2005 1 6 1 1DEC2005 31DEC2005 ; run;

When using retain I must sort by cycle,to avoid the error, not sorted; when sorting by date and then by cycle,i get no cycleid's.

can someone show me a way how to do this?

Thank you very much


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