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 (February 2008, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 27 Feb 2008 22:55:30 -0500
Reply-To:     "Howard Schreier <hs AT dc-sug DOT org>"
              <schreier.junk.mail@GMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "Howard Schreier <hs AT dc-sug DOT org>"
              <schreier.junk.mail@GMAIL.COM>
Subject:      Re: Calculating subgroups

On Wed, 27 Feb 2008 20:24:51 -0500, Anthony Pitruzzello <tonypit45@YAHOO.CA> 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