```Date: Mon, 14 May 2001 11:15:43 -0400 Reply-To: Richard DeVenezia Sender: "SAS(r) Discussion" From: Richard DeVenezia Organization: MindSpring Enterprises Subject: Re: Eligibility, Dates and Arrays Thomas: Here is a sample that will do what you want. data coverage_1992 ; input id m1-m12 eligible_months; format m1-m12 2.; cards; 101 1 1 1 1 1 1 1 1 1 1 1 1 12 102 1 1 1 1 1 1 1 1 0 0 0 0 8 103 0 0 0 0 1 1 1 1 1 1 0 0 6 104 0 0 0 1 1 1 1 1 1 1 1 1 9 105 1 1 1 0 0 1 1 1 1 1 1 1 10 106 0 0 1 1 1 1 0 0 1 1 1 0 7 ; data coverage_range; set coverage_1992; if sum (of m1-m12) NE eligible_months then put "Eligible months in file does not agree with calculated. " ID=; array m m1-m12 dummy; array s start1-start6; array e end1-end6; format start1-start6 end1-end6 mmddyy8.; i = 1; j = 1; do while (i < 13); * look for a start of a range; do while (i < 13 and m[i] eq 0); i ++ 1; end; if i < 13 then do; * found a start, assign the start date; s[j] = mdy (i, 1, 1992); * look for the end of the range; do while (i < 13 and m[i] eq 1); i ++ 1; end; * found the end, assign the end date; * the end month is i-1, the end date is one * day before the start of the next month; e[j] = intnx ('month', mdy (i-1, 1, 1992), 1) - 1; end; j ++ 1; end; drop i j dummy; run; -- Richard DeVenezia - SAS Macros and AF Tools http://www.devenezia.com "Foy, Thomas M." wrote in message news:606B4BC0D5B8D4118FB800805F19A75D01D44FFC@mail.hsmnet.com... > SAS Users and Masters: > > I need help/assistance with a data set I am working with. I have a health > care eligibility file that I need to read through and determine start dates > and end dates. The file contains data for one calendar year, each persons' > eligibility for coverage is denoted by a flag in a variable for each month, > and their total eligible months is in a another variable. What I need to > do is to read through each record, count the flags, and determine a start > date and end date. The file looks like the following: > > ID# M1 M2 M3 M4 M5 M6 M7 M8 M9 M10 > M11 M12 Eligible_Months > 101 1 1 1 1 1 1 1 1 > 1 1 1 1 12 > 102 1 1 1 1 1 1 1 1 > 0 0 0 0 8 > 103 0 0 0 0 1 1 1 1 > 1 1 0 0 6 > 104 0 0 0 1 1 1 1 1 > 1 1 1 1 9 > 105 1 1 1 0 0 1 1 1 > 1 1 1 1 10 > 106 0 0 1 1 1 1 0 0 > 1 1 1 0 7 > > Where M1 is January, M2 is February, ...M12 is December, and Eligible_Months > is the total number of months that person was eligible for coverage that > year. If Eligible_Months is 12 then it's not a problem, the start date is > 01Jan-year and the end date is 31DEC-year. It's when the person has less > than 12 months of eligibility that I am having trouble with. ID#'s 105 an > 106 are a particular problem with multiple start and end dates. In those > cases I need to string them together on one line such as; start_1 end_1 > start_2 end_2 .... With the total eligible months at the end. > > This problem is screaming for an array. But I'm not entirely sure how to go > about reading the elements until I get to the first non-zero element, and > then stopping at the last non-zero element. When I determine what the start > and end months are I will need to assign an actual date to them, i.e. > start_1 = 01Jan1999, end_1 = 31Aug1999. > > Any assistance with this will be greatly appreciated. > > Thank you, > > Thomas M. Foy > Sr. Research Programmer/Analyst > Park Nicollet Institute > Health Research Center > Minneapolis, Minnesota 55416 ```

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