Date: Wed, 9 Mar 2011 10:47:13 -0500
Reply-To: Dave <david.brewer@UC.EDU>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Dave <david.brewer@UC.EDU>
Subject: Re: Gap Determination
Content-Type: text/plain; charset=ISO-8859-1
Haikuo,
Thank you for the explanation...that helps.
Dave
On Wed, 9 Mar 2011 09:37:22 -0500, Bian, Haikuo <HBian@FLQIO.SDPS.ORG>
wrote:
>Dave,
>
>I am new to PRX as well, that is why I am so looking forward to Toby's
new book on PRX. Here is the code with comments:
>
>
>data have (drop=uncover start stop position length);
>infile cards;
> if _n_=1 then uncover=prxparse("/(0 )+/"); *To define the gap pattern
as "0" plus a blank.;
> retain uncover;
>
>input ID JAN1 FEB1 MAR1 APR1 MAY1 JUN1 JUL1 AUG1 SEP1 OCT1 NOV1 DEC1;
>start=countc(id,"0123456789")+1;*To start looking for the gap pattern
right after "id" ends;
>stop=lengthn(_infile_);
>call prxnext (uncover, start,stop, _infile_, position, length); *To
capture the gap pattern within _infile_ buffer;
>gap_ct=0;
>do while (position>0);*do loop to count the total number of gaps;
>gap_ct+1;
>call prxnext (uncover, start,stop, _infile_, position, length);
>end;
>gap_Len_Total=countc(_infile_,"0"); *To get the total length of gaps;
>gap_Len_avg=gap_Len_Total/gap_ct;
>cards;
>123 0 0 1 1 0 1 0 1 1 1 1 1
>222 1 1 1 1 1 1 1 1 1 1 1 1
>333 0 0 0 0 0 0 0 0 0 0 0 0
>;
>run;
>
>
>To understand the code above, you will need 2 parts of knowledge, and
they are both straightforward:
>1. the concept and usage of _infile_ variable,
>2. Some PRX functions.
>
>HTH,
>Haikuo
>
>
>
>
>-----Original Message-----
>From: Dave Brewer [mailto:david.brewer@UC.EDU]
>Sent: Wednesday, March 09, 2011 9:00 AM
>To: SAS-L@LISTSERV.UGA.EDU; Bian, Haikuo
>Subject: Re: Gap Determination
>
>Haikuo
>
>I don't quite understand your solution as I don't really understand PRX.
>
>Would you please explain using comments what you are doing?
>
>Thanks for your help.
>Dave
>
>On Fri, 4 Mar 2011 07:53:53 -0500, Bian, Haikuo <HBian@FLQIO.SDPS.ORG>
>wrote:
>
>>Dave,
>>
>>Here is another approach involving PRX:
>>
>>data have (drop=uncover start stop position length);
>>infile cards;
>> if _n_=1 then uncover=prxparse("/(0 )+/");
>> retain uncover;
>>
>>input ID JAN1 FEB1 MAR1 APR1 MAY1 JUN1 JUL1 AUG1 SEP1 OCT1 NOV1 DEC1;
>>start=countc(id,"0123456789")+1;
>>stop=lengthn(_infile_);
>>call prxnext (uncover, start,stop, _infile_, position, length);
>>gap_ct=0;
>>do while (position>0);
>>gap_ct+1;
>>call prxnext (uncover, start,stop, _infile_, position, length);
>>end;
>>gap_Len_Total=countc(_infile_,"0");
>>gap_Len_avg=gap_Len_Total/gap_ct;
>>cards;
>>123 0 0 1 1 0 1 0 1 1 1 1 1
>>222 1 1 1 1 1 1 1 1 1 1 1 1
>>333 0 0 0 0 0 0 0 0 0 0 0 0
>>;
>>run;
>>
>>proc print;
>>run;
>>
>>
>>Regards,
>>Haikuo
>>
>>
>>-----Original Message-----
>>From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Dave
>Brewer
>>Sent: Friday, March 04, 2011 5:32 AM
>>To: SAS-L@LISTSERV.UGA.EDU
>>Subject: Re: Gap Determination
>>
>>Soren,
>>
>>Thank you for your elegant solution.
>>
>>Dave
>>
>>On Fri, 4 Mar 2011 03:00:51 -0500, S=?ISO-8859-1?Q?=C3=B8ren?= Lassen
>><s.lassen@POST.TELE.DK> wrote:
>>
>>>Dave,
>>>A slight simplification of Taylor's string solution:
>>>
>>>data ins;
>>> input ID:$4. JAN1 FEB1 MAR1 APR1 MAY1 JUN1 JUL1 AUG1 SEP1 OCT1 NOV1
>>DEC1
>>> JAN2 FEB2 MAR2 APR2 MAY2 JUN2 JUL2 AUG2 SEP2 OCT2 NOV2
>>DEC2;
>>> str=cat(of jan1--dec2);
>>> uninsured=count(str,'0');
>>> ngaps=count('1'!!str,'10');
>>> array gaps gap1-gap12;
>>> do _N_=1 to ngaps;
>>> gaps(_N_)=length(scan(str,_N_,'1'));
>>> end;
>>> if uninsured then
>>> avggap=uninsured/ngaps;
>>> drop str;
>>>cards;
>>>123 0 0 1 1 0 1 0 1 1 1 1 1 0 0 1 1 0 1 0 1 1 1 1 1
>>>222 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
>>>333 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
>>>;run;
>>>
>>>The number of gaps is easily calculated by prefixing the string with
>>>'1' and counting the number of '10' transitions. That known, you
>>>do not really need the length of the individual gaps to calculate
>>>the average gap length - but as you had specified that you wanted them,
>>>I included code to calculate them using an array.
>>>
>>>Regards,
>>>Søren
>>>
>>>
>>>On Wed, 2 Mar 2011 14:14:37 -0500, Dave <david.brewer@UC.EDU> wrote:
>>>
>>>>Hi SAS-Lers
>>>>
>>>>I have a data set with 24 variables (JAN1-DEC1, JAN2-DEC2), each
>>>>containing a 1 (has insurance coverage) or 0 (no insurance coverage).
>>>>
>>>>I need to find the following information for each person:
>>>> 1) Cumulative number of months an individual does not have insurance.
>>>> 2) Number of gaps in insurance (a patient could have a gap, become
>>>>insured and a gap again...thus the number of gaps would be 2 in this
>>case)
>>>> 3) The length of each gap (measured in months)...call this GapLength1,
>>>>GapLength2, etc.
>>>> 4) The average gap length.
>>>>
>>>>Data looks like this (for sake of brevity, I am only showing the first
>12
>>>>months):
>>>>
>>>>ID JAN1 FEB1 MAR1 APR1 MAY1 JUN1 JUL1 AUG1 SEP1 OCT1 NOV1 DEC1
>>>>123 0 0 1 1 0 1 0 1 1 1 1 1
>>>>222 1 1 1 1 1 1 1 1 1 1 1 1
>>>>333 0 0 0 0 0 0 0 0 0 0 0 0
>>>>
>>>>Thanks for your help.
>>>>Dave
>>-----------------------------------------
>>Email messages cannot be guaranteed to be secure or error-free as
>>transmitted information can be intercepted, corrupted, lost,
>>destroyed, arrive late or incomplete, or contain viruses. The
>>Centers for Medicare & Medicaid Services therefore does not accept
>>liability for any error or omissions in the contents of this
>>message, which arise as a result of email transmission.
>>
>>CONFIDENTIALITY NOTICE: This communication, including any
>>attachments, may contain confidential information and is intended
>>only for the individual or entity to which it is addressed. Any
>>review, dissemination, or copying of this communication by anyone
>>other than the intended recipient is strictly prohibited. If you
>>are not the intended recipient, please contact the sender by reply
>>email and delete and destroy all copies of the original message.
|