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

Dear All,

 

Can some one help with edit check. I have dataset with three collumns ID, DATE, TIME.

 

I have to write a program to confirm that  assessment time between two measurements should be at least 2 minute apart.I have to output the discripancies where the assessments are performed within 2minutes.

 

Below is the sample data.

 

10031001 28SEP2015 08:36

10031001 28SEP2015 08:38

10031001 28SEP2015 08:39

10031001 28SEP2015 08:40

10031001 28SEP2015 08:42

10031001 28SEP2015 08:44

10031001 28SEP2015 08:46

 10031002 28OCT2015 08:36

10031002 28OCT2015 08:39

10031002 28OCT2015 08:40

10031002 30OCT2015 08:40

10031002 30OCT2015 08:41

10031002 30OCT2015 08:43

10031002 30OCT2015 08:45

 

The output shoudl look like this

 

10031001 28SEP2015 08:38

10031001 28SEP2015 08:39

10031001 28SEP2015 08:40

10031002 28OCT2015 08:39

10031002 28OCT2015 08:40

10031002 30OCT2015 08:40

10031002 30OCT2015 08:41

 

Thanks in advance

Rakesh

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

Since you have to look ahead and back, I'd use something like the following:

 

data have;
  informat date date9.;
  informat time time5.;
  input ID date time;
  format date date9.;
  format time time5.;
  cards;
10031001 28SEP2015 08:36
10031001 28SEP2015 08:38
10031001 28SEP2015 08:39
10031001 28SEP2015 08:40
10031001 28SEP2015 08:42
10031001 28SEP2015 08:44
10031001 28SEP2015 08:46
10031002 28OCT2015 08:36
10031002 28OCT2015 08:39
10031002 28OCT2015 08:40
10031002 30OCT2015 08:40
10031002 30OCT2015 08:41
10031002 30OCT2015 08:43
10031002 30OCT2015 08:45
;

data have;
  set have;
  dt=input(catx(':',put(date,date9.),put(time,time5.)),anydtdtm15.);
  format dt datetime21.;
run;

data want (keep=id date time);
  set have;
  by ID;
  set have ( firstobs = 2 keep = dt rename = (dt = Next_dt) )
      have (      obs = 1 drop = _all_                      );
  Prev_dt = ifn( first.ID, (.), lag(dt) );
  Next_dt = ifn(  last.ID, (.), Next_dt );
  if not missing(Next_dt) and (Next_dt-dt) lt 120 then output;
  else if not missing(Prev_dt) and (dt-Prev_dt) lt 120 then output;
run;

Art, CEO, AnalystFinder.com

 

View solution in original post

3 REPLIES 3
Reeza
Super User

Look at DIF() function. 

If this is a check post your current code. 

art297
Opal | Level 21

Since you have to look ahead and back, I'd use something like the following:

 

data have;
  informat date date9.;
  informat time time5.;
  input ID date time;
  format date date9.;
  format time time5.;
  cards;
10031001 28SEP2015 08:36
10031001 28SEP2015 08:38
10031001 28SEP2015 08:39
10031001 28SEP2015 08:40
10031001 28SEP2015 08:42
10031001 28SEP2015 08:44
10031001 28SEP2015 08:46
10031002 28OCT2015 08:36
10031002 28OCT2015 08:39
10031002 28OCT2015 08:40
10031002 30OCT2015 08:40
10031002 30OCT2015 08:41
10031002 30OCT2015 08:43
10031002 30OCT2015 08:45
;

data have;
  set have;
  dt=input(catx(':',put(date,date9.),put(time,time5.)),anydtdtm15.);
  format dt datetime21.;
run;

data want (keep=id date time);
  set have;
  by ID;
  set have ( firstobs = 2 keep = dt rename = (dt = Next_dt) )
      have (      obs = 1 drop = _all_                      );
  Prev_dt = ifn( first.ID, (.), lag(dt) );
  Next_dt = ifn(  last.ID, (.), Next_dt );
  if not missing(Next_dt) and (Next_dt-dt) lt 120 then output;
  else if not missing(Prev_dt) and (dt-Prev_dt) lt 120 then output;
run;

Art, CEO, AnalystFinder.com

 

rakeshvvv
Quartz | Level 8

Thank you Sir for the quick reply......

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 3 replies
  • 1419 views
  • 1 like
  • 3 in conversation