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
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
Look at DIF() function.
If this is a check post your current code.
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
Thank you Sir for the quick reply......
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.