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 (August 2011, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 26 Aug 2011 05:53:35 -0400
Reply-To:     Dave Brewer <david.brewer@UC.EDU>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Dave Brewer <david.brewer@UC.EDU>
Subject:      Re: Gap Question, Part 3
Comments: To: Søren Lassen <s.lassen@POST.TELE.DK>
Content-Type: text/plain; charset=ISO-8859-1

Hi Søren,

Thanks much for your help...works like a charm!

Dave

On Fri, 26 Aug 2011 03:38:08 -0400, S=?ISO-8859-1?Q?=C3=B8ren?= Lassen <s.lassen@POST.TELE.DK> wrote:

>Dave, >Here is a simple solution (no PRX, no loop, just character functions): > >data dave2 (keep=Ngaps number_zeros Avg_Gap_Length); >input jan1 feb1 mar1 apr1 may1 jun1 jul1 aug1 sep1 oct1 nov1 dec1 >jan2 feb2 mar2 apr2 may2 jun2 jul2 aug2 sep2 oct2 nov2 dec2; >seq=catt(of jan1--dec2); >/* convert zeros to blanks */ >seq=translate(seq,' ','0'); >/* delete single ones (neither coverage nor gaps) and preceding zeros */ >seq=left(tranwrd(' '!!seq,' 1 ',' ')); >if length(seq) then do; /* if any coverage at all */ > /* ngaps=number of "words" -1 - in SAS 9.2 you can also use COUNTW */ > ngaps=count(seq,'1 ')-1; > /* total length of gaps */ > number_zeros=length(seq)-length(compress(seq)); > /* if there are no gaps, the average length stays missing */ > if ngaps then > avg_gap_length=number_zeros/ngaps; > end; >cards; >1 1 1 1 1 1 1 1 0 0 1 1 1 1 1 0 0 0 0 1 1 1 1 1 >1 1 0 0 1 1 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 >1 1 0 1 0 1 1 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 >; >run; > >Regards, >Søren > > > >On Thu, 25 Aug 2011 08:42:11 -0400, Dave <David.brewer@UC.EDU> wrote: > >>Hi SAS-Lers, >> >>I am still struggling trying to get a solution that will solve my problem. >> >>I am trying to capture the following: >> >>The pattern we are looking for is anyone with at least two consecutive >>months of insurance coverage (the one's), at least one month without >>coverage (the zeroes), and then regains coverage for at least two >>consecutive months. WE need to calculate the number of patterns like this, >>the average time without insurance during the pattern, and the total >>number of cumulative months without insurance. >> >>So: >>1 1 0 0 1 1 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 >> >>Average gap length should be 2.5 (2+3/2). Number of months without >>insurance within the pattern should be 5. Number of gaps should be 2. >> >>Another example: >>1 1 1 1 1 1 1 1 0 0 1 1 1 1 1 0 0 0 0 1 1 1 1 1 >> >>The average gap length should be 3 (not 2.667); number of gaps should be >>2, cumulative months within gap should be 6. >> >>Yu Zhang provided the following code, and now I have new criteria that I >>need to modify his code, but I just can't quite get it to work. >> >>data dave2 (keep=Ngaps number_zeros Avg_Gap_Length); >>call missing(Ngaps,number_zeros); >>input jan1 feb1 mar1 apr1 may1 jun1 jul1 aug1 sep1 oct1 nov1 dec1 >>jan2 feb2 mar2 apr2 may2 jun2 jul2 aug2 sep2 oct2 nov2 dec2; >>seq=catt(of jan1--dec2); >> >>ExpressionID=prxparse('/1{2}0+(?=1{2})/'); >> >>call prxsubstr(ExpressionID, seq, position, length); >>number_zeros=0; >>do while(position~=0); >> Ngaps+1; >> match = substr(seq, position, length); >> seq=substr(seq,length+1); >> call prxsubstr(ExpressionID, seq, position, length); >> x=count(match,'0'); >> number_zeros+count(match,'0'); >>end; >>Avg_Gap_Length=round(number_zeros/Ngaps); >> >>cards; >>1 1 1 1 1 1 1 1 0 0 1 1 1 1 1 0 0 0 0 1 1 1 1 1 >>1 1 0 0 1 1 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 >>; >>run; >> >>proc print noobs; >>run; >> >>Can anyone help me find the number of gaps, gap length, and average gap >>length (number of months w/o insurance)? >> >>Thanks everybody for your help. Hopefully I made myself clear. >>Dave


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