BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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!
2 REPLIES 2
Doc_Duke
Rhodochrosite | Level 12
The LAG function provides the functionality that you are looking for. It's available through the data step.

Doc Muhlbaier
Duke
yonib
SAS Employee
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;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 706 views
  • 0 likes
  • 3 in conversation