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 12:09:19 -0500
Reply-To:     Ian Whitlock <WHITLOI1@WESTAT.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Ian Whitlock <WHITLOI1@WESTAT.COM>
Subject:      Re: Do while tip
Content-Type: text/plain; charset="iso-8859-1"

Jp,

If I understand you (from 111 or 333 until a stop value change values to this value, repeat throughout the array) then the following code works. It is an interesting case because efficiency demands that the value if I be changed inside the loop.

data c2b ; retain jour1 - jour663 0 ; idbenef = 1407 ; input jour1 - jour40 ; cards ; 0 0 0 0 0 0 0 0 30 30 30 333 0 0 0 21 21 21 30 30 30 30 333 0 0 0 0 0 30 30 30 30 333 21 21 1 2 3 0 111 ; DATA c2c ( drop = i j value ) ; SET c2b (WHERE = (idbenef = 1407)); ARRAY sjr{*} jour1-jour663; jour400 = 63 ; *added for test only ; DO i = 1 by 1 until ( i >= dim ( sjr ) ) ; if ( sjr{i} IN(111,333) ) then do ; value = sjr ( i ) ; do j = i + 1 to dim ( sjr ) while (sjr{j} NOT IN(.,21,22,23,24,30,31,32, 51,52,53,54,61,62,63,64,35,45)) ; sjr{j} = value; end ; i = j ; end ; END; RUN;

Ian Whitlock <whitloi1@westat.com>

-----Original Message----- From: JP [mailto:R_E_M_O_V_E_lecruguel@EPID.JGH.MCGILL.CA] Sent: Tuesday, November 21, 2000 10:46 AM To: SAS-L@LISTSERV.UGA.EDU Subject: Do while tip

Hi all,

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

To do that, I tried with the DO WHILE loop. I do not exactly get what I need, and it extremely long, and I would like to optimize my code.

DATA c2c; SET c2b (WHERE = (idbenef = 1407)); ARRAY sjr{*} jour1-jour663; DO i = 1 TO DIM(sjr)-1; IF sjr{i} IN(111,333) THEN DO; DO WHILE (sjr{i+1} NOT IN(.,21,22,23,24,30,31,32,51,52,53,54,61,62,63,64,35,45)); IF sjr{i}= 111 THEN sjr{i+1} = 111; ELSE IF sjr{i}= 333 THEN sjr{i+1} = 333; END; END; END; RUN;

a graph of the data and where to look at: 0 0 0 0 0 0 0 0 30 30 30 333 0 0 0 21 21 21 30 30 30 30 333 0 0 0 0 0 30 30 30 30 333 21 21 .... ------------------------------x---------------------------------x----------- ----------------y------ What I want: Same thing but, the 0 or whatever after the "x" shoule be changed to 333 ------------------------------x 333 333 333-------------------x 333 333 333 333 333 ---y------

For the last bit (y), there is nothing to change, as the next day is in the "stop" list.

There must be an option with the DO WHILE. I checked STOP and RETURN but they seem to stop completely or to go to the next obs.

Any tip? JP

PS: sorry if this appears twice.


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