All listers, My loop is not working. Here’s the scenario. This is
medical eligibility data. I have a start date and an end date for each member. Memberid startdate enddate 01 01/01/2010 12/31/2010 So there is one line for each eligibility period per member.
I need to expand this so that I have one line for each month of eligibility
with a new string variable that looks like this: Yearmonth 201001 201002 201003 . . . 201012 This is not an spss date format so it is just a string. Of
course eligibility periods can cross years. This is just an example. An
actuarial firm is requesting the data in this format. The following do- if
statement works if I do this for one month at a time. *################# I first transform the
startdate into month_year1. string month_year1(a6). compute month_year1 =
concat(char.substr(string(elig_start_date, adate10), 7, 4),
char.substr(string(elig_start_date, adate10), 1,2)). exe. *############# Then
I take month_year1 and add one to the month if the month’s not 12, and if
the month’s 12 I make the next month ‘01’ and increment the
year. *############# This
works fine. string month_year2(a6). string #month(a2). string #year(a4). do if number(char.substr(month_year1, 5,2), f2) < 12. compute #month =
lpad(ltrim(string(number(char.substr(month_year1, 5,2),f2) + 1,f2)),2,'0'). compute #year
= string(number(char.substr(month_year1, 1,4),f4)
,f4). else. compute #month = '01'. compute #year =
string(number(char.substr(month_year1, 1,4),f4) + 1,f4). end if. compute month_year2 = concat(#year, #month). exe. *############# But
if I put this in a loop I get blank cells. Not system missing, but blanks. I
want this to end when the newly created month_year equals enddate, hence the
end-loop-if *############# statement. The loop goes to 20 because the
maximum number of months for any eligibility period is 20 months. There is a
month_year21 because the range is *#############
inclusive. The loop only goes to 20 because the final compute month_year(#I +
1) fills in the value for month_year21. string month_year3 to month_year21(a6). string #month(a2). string #year(a4). vector month_year = month_year2 to month_year20. loop #I = 2 to 20. do if
number(char.substr(month_year(#I), 5,2), f2) < 12. compute #month
= lpad(ltrim(string(number(char.substr(month_year(#I), 5,2),f2) +
1,f2)),2,'0'). compute #year
= string(number(char.substr(month_year(#I),
1,4),f4) ,f4). else. compute #month =
'01'. compute #year
= string(number(char.substr(month_year(#I), 1,4),f4) + 1,f4). end if. compute
month_year(#I+1) = concat(ltrim(#year), ltrim(#month)). end loop if (#month = char.substr(string(elig_end_date,
adate10), 1,2)) & (#year =
char.substr(string(elig_end_date, adate10),7,4)). exe. Any help would be much appreciated. Efficiencies that could
be realized in the code are also more than welcome. Thanks! Matt Matthew Pirritano, Ph.D. Research Analyst IV Medical Services Initiative (MSI) Orange County Health Care Agency (714) 568-5648 |
Forget it. I guess the issue was that vectors must start at 1. Maybe that should have been obvious.
|
Free forum by Nabble | Edit this page |