This is a difficult problem, and if you are having trouble explaining it, then you can't begin to program it. Assuming you have explained it properly, here's an outline of how I would attack this sort by ID and dos In a data step, assign a unique (sequential) hospital admission number (I am assuming that each hospital admission in the table is unique, and then the other admissions that follow that don't say hospital are related to the previous hospital admission) Within each unique hospital admission number, find the dos for the hospital admission and the minimum dos for each hospice, skilled, rehab, nursing, etc. This can probably done via PROC MEANS or PROC SUMMARY recombine all of this so that each unique hospital admission number also has the minimum dos for each hospice, skilled, etc. on the same row so you can see if the subsequent admission was within 30 days once step 4 is complete, this tells you how to allocate each row of the original table (actually the table from step 2)
... View more