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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 580 views
  • 0 likes
  • 3 in conversation