I am working on the HCUP State Inpatient Database which contains revenue
codes and associated charges and units for each patient discharge. The layout is that Revenue code = Charges = Units, e.g. revcd1 = chgs1 = units1. I have created two vectors to scan through the revenue codes and if it makes certain conditions to pull out the associated charge from chgsn and sum across all charges if more than one revenue code variable meets the condition and likewise with units, sum all appropriate units. For example, I want to test for the revenue codes of 011, 012 and 013 which are for routine room & board charges and then sum all the charges in revcdn that meet the condition for a total routine charges. Any revenue code variable can contain any of the specified revenue codes. In the code below, the vector only picks the 3rd of 3 revenue code variables and adds it to the new variable routinecharges. It does not sum the other two revenue code variables. What should happen is case 1 should be 6000 not 5000, case 2 should be 4000 not 2000, etc. Likewise, I need to do the same for units. I'm pretty close but can't seem to find the right code to do what I want. I appreciate any help on this. John Welton, MUSC Charleston, SC DATA LIST FIXED / provnumb 1-3 (A) revcd1 5-8 (A) revcd2 10-13 (A) revcd3 15-18 (A) chgs1 20-23 chgs2 25-28 chgs3 30-33 units1 35-35 units2 37-37 units3 39-40. variable labels provnumb "Provider number" revcd1 "Revenue code 1" revcd2 "Revenue code 2" revcd3 "Revenue code 3" chgs1 "Charges 1" chgs2 "Charges 2" chgs3 "Charges 3" units1 "Units 1" units2 "Units 2" units3 "Units 3" . BEGIN DATA. 001 011X 021X 011X 1000 2000 5000 2 1 10 001 011X 011X 013X 1000 1000 2000 2 2 20 002 013X 021X 023X 1000 1000 0750 2 1 15 END DATA. LIST. VECTOR V1=revcd1 to revcd3. VECTOR V2=chgs1 to chgs3. STRING revcdstring (A3). LOOP number=1 to 3. COMPUTE routinechgs = 0. COMPUTE revcdstring = substr(V1(number),1,3). IF ANY(revcdstring,"011","012","013") routinechgs = sum(V2(number)). END LOOP. VECTOR V3=revcd1 to revcd3. VECTOR V4=units1 to units3. STRING revcdstring2 (A3). LOOP number2=1 to 3. COMPUTE routinedays = 0. COMPUTE revcdstring2 = substr(V3(number2),1,3). IF ANY(revcdstring2,"011","012","013") routinedays = routinedays + V4(number2). END LOOP. EXECUTE. DELETE VARIABLES number number2. |
At 05:35 PM 1/21/2007, John wrote:
>The layout [of my record] is that Revenue code [corresponds to] >Charges [corresponds to] Units, e.g. revcd1 [corresponds to] chgs1 >[corresponds to] units1. >I have created two vectors to scan through the revenue codes and if it >makes certain conditions to pull out the associated charge from chgsn >and sum across all [such] charges. [...] In the code below, the vector >only picks the 3rd of 3 revenue code variables and adds it to the new >variable routinecharges. I don't think this is too bad. You have, >DATA LIST FIXED / provnumb 1-3 (A) > revcd1 5-8 (A) revcd2 10-13 (A) revcd3 15-18 (A) > chgs1 20-23 chgs2 25-28 chgs3 30-33 > units1 35-35 units2 37-37 units3 39-40. [Remainder of data definition appreciated, but not needed for what I'm writing.] >VECTOR V1=revcd1 to revcd3. >VECTOR V2=chgs1 to chgs3. > >STRING revcdstring (A3). > > LOOP number=1 to 3. > COMPUTE routinechgs = 0. > COMPUTE revcdstring = substr(V1(number),1,3). > IF ANY(revcdstring,"011","012","013") > routinechgs > = sum(V2(number)). > END LOOP. There above is your logic problem. a. You set 'routinechgs' to 0 every time through the loop, rather than once, before the loop begins. b. (This is even more crucial.) You compute 'routinechgs' as 'sum(V2(number))'. That's 'SUM' with just one argument; the result is the value of 'V2(number)'. You write that "the vector only picks the 3rd of 3 revenue code variables". Exactly: 'routinechgs' will have the value it got the last time the 'IF' tests true; the last charge, not the sum of charges, meeting the test for "routine". Recast as follows: . COMPUTE routinechgs = 0 /* Move outside the loop */. . LOOP number=1 to 3. . COMPUTE revcdstring = substr(V1(number),1,3). . IF ANY(revcdstring,"011","012","013") routinechgs = sum(V2(number) ,routinechgs) /* Sum with current value */. . END LOOP. This should do it. Further, a. If any 'charge' value is missing, this will treat it as if it were 0. That may well be what you want. b. Variables "revcdstring" and "number" could well be made scratch variables, so they won't appear in the final file. -Good luck, Richard |
Free forum by Nabble | Edit this page |