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 2007, week 5)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Wed, 30 May 2007 05:01:37 GMT
Reply-To:   Theorbo <reply@TO-GROUP.NFO>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Theorbo <reply@TO-GROUP.NFO>
Subject:   creating an increment that resets - how?
Comments:   To: sas-l@uga.edu
Content-Type:   text/plain; format=flowed; charset="iso-8859-1"; reply-type=original

Hi everyone.

OK, I've been trying to figure this out for the past several hours so I am going to turn to the experts. If you can help point me in the right direction, that would be a good start.

I have four columns of data, the first two are lengths of time the third is a clock-like timer. The last column shows what I am trying to duplicate with logic.

I need to keep track of the periods of time (timegroup variable) when both lengths are not zero. For instance, after the first three observations, the next four observations would have the timegroup value of 1, then the next two observations have zero values for both lengths so skip these. Then the next three obs would have the timegroup value of 2.

The kicker is that when the third column variable, clockcount, resets to 1, I need my timegroup values to restart at 1. So I've been trying to use do while and do until loops with lag() but have had no success.

I tried thinking about what I want to do in plain english and came up with this ...

// SET TIMEGROUP = 0 DO THIS WHILE CLOCKCOUNT NE 1 IF (LENGTH1+LENGTH2) gt 0 AND LAG1(TIMEGROUP) eq 0 THEN TIMEGROUP + 1 KEEP TIMEGROUP VALUE UNTIL LENGTH1+LENGTH2 eq 0 AND LAG1(TIMEGROUP) gt 0 END RETURN TO TOP //

Any tips or suggestions? Thanks very much for your time.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ DATA timetest; INFILE DATALINES DELIMITER=','; INPUT length1 length2 clockcount checknum; DATALINES; 0,0,1, 0,0,2, 0,0,3, 20,15,4,1 10,0,5,1 5,0,6,1 0,20,7,1 0,0,8, 0,0,9, 0,15,10,2 15,15,11,2 20,10,12,2 0,0,13, 0,0,14, 0,0,15, 0,0,16, 0,0,1, 0,0,2, 5,5,3,1 0,10,4,1 0,0,5, 0,0,6, 20,15,7,2 10,0,8,2 5,0,9,2 0,20,10,2 0,0,11, 0,0,12, 0,15,13,3 15,15,14,3 20,10,15,3 0,0,16, 0,0,17, 0,0,18, 0,0,19, 0,0,20, ; RUN;

PROC PRINT DATA = timetest; RUN;


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