BookmarkSubscribeRSS Feed
sunilsan
Calcite | Level 5

we have visit, visit_date, and pt (patient) variables or fields are there

pt    --     visit   --      visit_date

10005    visit 1        01-jan-2020
10005    visit 2        09-jan-2020
10005    visit 3        11-jan-2020
10005    visit 4         02-jan-2020
10005    visit 5        03-jan-2020

requirement is the date entered is wrong,
the visit 1 date always smaller than visit 2 , same way visit 2 dae smaller than visit 3

but here visit 4 date is date shd be gretaer than visit 3 ..
how to find these type of patient information date information in our raw data

2 REPLIES 2
Reeza
Super User

FYI - I have updated your subject line to be more descriptive of your question. In the future please use an appropriate subject line. 

I see you've provided input data, what do you want as output?

 

One function of interest is the DIF() function. It will calculate the difference between the current row and previous row. So if you calculate the dif for the date column you can then check if the dates are increasing or decreasing. 

 

You may also want to make sure your example data is representative of your problem. Do you have multiple patients for example? The code will change if you need to do it for multiple or just one. I'll leave that to you for now. An example of a possible solution is below:

 

data want;
set have;

days_diff = dif(visit_date);

if days_diff <0 then flag="ERROR";

run;

@sunilsan wrote:

we have visit, visit_date, and pt (patient) variables or fields are there

pt    --     visit   --      visit_date

10005    visit 1        01-jan-2020
10005    visit 2        09-jan-2020
10005    visit 3        11-jan-2020
10005    visit 4         02-jan-2020
10005    visit 5        03-jan-2020

requirement is the date entered is wrong,
the visit 1 date always smaller than visit 2 , same way visit 2 dae smaller than visit 3

but here visit 4 date is date shd be gretaer than visit 3 ..
how to find these type of patient information date information in our raw data


 

Ksharp
Super User

If PT was group variable.

 

data want;
set have;

days_diff = dif(visit_date);

if pt=lag(pt) and days_diff <0 then flag="ERROR";

run;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 542 views
  • 1 like
  • 3 in conversation