Help using Base SAS procedures

edit checks

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 145
Accepted Solution

edit checks

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….


Accepted Solutions
Solution
‎11-19-2015 01:03 PM
Super User
Super User
Posts: 7,407

Re: edit checks

Use lag function:

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

View solution in original post


All Replies
Super User
Posts: 5,257

Re: edit checks

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

Data never sleeps
Solution
‎11-19-2015 01:03 PM
Super User
Super User
Posts: 7,407

Re: edit checks

Use lag function:

data check;
  set have;
  if lag(enddtc) - stdtc ne 1 then flag="Y";
run;
Super User
Posts: 17,850

Re: edit checks

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.
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 280 views
  • 0 likes
  • 4 in conversation