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 2000, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Tue, 21 Nov 2000 11:39:50 -0500
Reply-To:   "Fehd, Ronald J." <rjf2@CDC.GOV>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   "Fehd, Ronald J." <rjf2@CDC.GOV>
Subject:   Re: Do while tip
Content-Type:   text/plain; charset="iso-8859-1"

> From: JP [mailto:R_E_M_O_V_E_lecruguel@EPID.JGH.MCGILL.CA] > I have a problem with some data manipulation and the DO while loop. > > What I want is to read an array of 663 days. Each day has a status. > If the current day has a given status (=111 or 333), then I > want to change > all the following days to status 111 or 333 until I reach a > day with another > given status (.,21,22,23,24,30,31,32,51,52,53,54,61,62,63,64,35,45). > If it reaches one of this status, I want it to stop changing > status, but to > continue looking for 111 and 333 status. > DO WHILE goes to the end the array each time it finds a 111 > or a 333. I would like it to stop

You have become entangled in your logic, an unfortunate thing but the usual result of trying to do what you thought you wanted to do rather than doing what are supposed to do: think less, program less.

it seems to me that you want to do several things: 1. search for a given status: 111 or 333 if found then save that status and set a flag to change 2. search for a second status to switch back to not changing status 3. change status based on flag

so: data CURRENT; array S(*) <Status variables>; drop I; retain Is_111_or_333 0 NewStatus 0 ChangeWanted 0; set PREVIOUS; do I = 1 to dim(S); if not Is_111_or_333 then do;Is_111_or_333 = S(I) in (111,333); if Is_111_or_333 then do;ChangeWanted = 1; NewStatus = S(I); end; ChangWanted = S(I) not in (<the other list of Status codes>); if ChangWanted then S(I) = NewStatus; %*do I=1:dim;end;

Ron Fehd the logic and semaphore maven CDC Atlanta GA USA RJF2@cdc.gov OpSys: WinNT Ver: 8.1 ---> cheerful provider of UNTESTED SAS code!*! <--- e-mail your SAS improvements to: suggest@sas.com archives: http://www.listserv.uga.edu/archives/sas-l.html By using your intelligence you can sometimes make your problems twice as complicated. remember perspective: the error is not always where it seems to occur! -- RJF2


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