Desktop productivity for business analysts and programmers

summarizing subsequent data rows

Not applicable
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!
Trusted Advisor
Posts: 2,127

Re: summarizing subsequent data rows

Posted in reply to deleted_user
The LAG function provides the functionality that you are looking for. It's available through the data step.

Doc Muhlbaier
SAS Employee
Posts: 105

Re: summarizing subsequent data rows

Posted in reply to deleted_user

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 $;
format num22 mmddyy10. num33 mmddyy10.;
if ind=num22 or ind=num22-1 then new=1;
else if ind=. then new=1;
else new=2;
put _all_;
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
Ask a Question
Discussion stats
  • 2 replies
  • 3 in conversation