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

Missed SAS Innovate in Orlando?

Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.

 

Register now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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