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-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!

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.

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