```Date: Wed, 27 Feb 2008 22:55:30 -0500 Reply-To: "Howard Schreier " Sender: "SAS(r) Discussion" From: "Howard Schreier " Subject: Re: Calculating subgroups On Wed, 27 Feb 2008 20:24:51 -0500, Anthony Pitruzzello wrote: >I have a data set that looks basically like this: > >ID Week >1 2 >1 3 >1 >1 5 >1 6 >1 7 >2 1 >2 2 >2 >2 4 >2 >2 > >The ID represents a student. The week represents those weeks (out of a 6 week period) where the student was in attendance at a given building. I want to calculate consecutive attendance. So, for student number 1, the first consecutive attendance period spans two weeks and the second spans three weeks. For student number 2, the first spans two weeks; the second, only one week. > >Can anyone share some code that does this? One way ... data have; infile cards missover; input ID Week ; cards; 1 2 1 3 1 1 5 1 6 1 7 2 1 2 2 2 2 4 2 2 ; First create a flag which is zero for a missing week or one for a positive week: data forsumm / view = forsumm; set have; flag = not not week; run; Count; discard observations corresponding to interruptions: proc summary data=forsumm noprint; by id flag notsorted; output out = want(where = (flag > 0) ); run; Display: proc print data=want; by id; id id; var _freq_; run; Result: ID _FREQ_ 1 2 3 2 2 1 ```

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