Desktop productivity for business analysts and programmers

summarizing subsequent data rows

Reply
N/A
Posts: 0

summarizing subsequent data rows

I am trying to summarize some medical claims data that is in multiple rows. I want to flag or create a counter for any rows that have an admit date that is the same or within one day of the previous row's discharge date. For instance:

ID Admit Discharge Counter
X 1/1/2008 1/15/2008 1
X 1/15/2008 1/30/2008 1
X 1/31/2008 2/10/2008 1
X 2/15/2008 2/30/2008 2

Hope that makes sense. The next and previous functions can do something similar to this in Crystal but I can't think of how to do it with SAS. Any ideas? Thanks!
Valued Guide
Posts: 2,111

Re: summarizing subsequent data rows

The LAG function provides the functionality that you are looking for. It's available through the data step.

Doc Muhlbaier
Duke
SAS Employee
Posts: 105

Re: summarizing subsequent data rows

Hey,

Here is an example of using lag function to get what you looking for base on your example:

data temp (drop=ind num2 num3);
length num3 $10.;
input num1 $ num2 $10. num3 $;
num22=input(num2,mmddyy10.);
num33=input(num3,mmddyy10.);
format num22 mmddyy10. num33 mmddyy10.;
ind=lag(num33);
if ind=num22 or ind=num22-1 then new=1;
else if ind=. then new=1;
else new=2;
put _all_;
cards;
x 01/11/2008 01/15/2008
x 01/15/2008 01/30/2008
x 01/31/2008 02/10/2008
x 02/15/2008 02/26/2008
;
run;
Ask a Question
Discussion stats
  • 2 replies
  • 85 views
  • 0 likes
  • 3 in conversation