BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
rakeshvvv
Quartz | Level 8

Hi,

I have dataset with four variables…..id, etcd ,stdtc, endtc

 

14615100010001               SCRN     2014-07-31          2014-08-05

14615100010001               COMB   2014-08-05          2014-11-13

14615100010001               1000394 2014-11-14         2014-11-17

14615100010001               SAFFU   2014-11-26          2014-12-23

14615100010001               SURVFU 2014-12-24        2015-04-28

14615100010003               SCRN     2015-02-19          2015-02-25

14615100010003               COMB   2015-02-25          2015-07-02

14615100010003               1000394 2015-07-03         2015-07-06

14615100010003               SURVFU 2015-08-12        2015-08-14

I want to write a query in such a way that I want to output the following

For every id, The difference between the  ENDTC and STDTC of next record should not be greater then1.

If the difference in greater then 1, we should output those. Those highlighted in yellow are discrepancies and we should output those.

 

Can someone help on this….

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Use lag function:

data check;
  set have;
  if lag(enddtc) - stdtc ne 1 then flag="Y";
run;

View solution in original post

3 REPLIES 3
LinusH
Tourmaline | Level 20

Use a data step w/ BY and RETAIN . An potentially the use of first. and last. logic.

Data never sleeps
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Use lag function:

data check;
  set have;
  if lag(enddtc) - stdtc ne 1 then flag="Y";
run;
Reeza
Super User
Because you want both records you need a look forward method. There are many ways to do this.
One way is to add a record indicator for each row and then use a sql merge to join with the record +1. Then you can create a flag to keep certain records. This is a well written topic though, so either searching on here or lexjansen.com should provide some good look ahead methods.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 3 replies
  • 1032 views
  • 0 likes
  • 4 in conversation