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

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!

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