Leon
Leon

Reputation: 429

SAS:minutes elapse calculation

+--------------+--------------+
| switch_time1 | switch_time2 |
+--------------+--------------+
| 8:00:15      | 8:32:15      |
| 9:12:13      | 9:18:13      |
| 18:20:36     | 18:46:36     |
+--------------+--------------+

how to use the right format of time calculation in SAS proc sql?

PROC SQL;
   CREATE TABLE MC_ET AS
   SELECT 
                sum(case when switch_time2-switch_time1>5 minutes and switch_time2-switch_time1<10mintues then 1 else 0 end) as Count_of_8,
                sum(case when switch_time2-switch_time1>10 minutes and switch_time2-switch_time1<15mintues then 1 else 0 end as count_of_9,      ...
      FROM have
;
QUIT;

Upvotes: 0

Views: 34

Answers (1)

Reeza
Reeza

Reputation: 21274

You were pretty close. Note that times are stored in seconds so multiply your conditions by 60 (5 minutes * 60 seconds/minute) = 300 seconds

PROC SQL;
   CREATE TABLE MC_ET AS
   SELECT 
                sum(case when switch_time2-switch_time1> (5*60) and switch_time2-switch_time1< (10*60) then 1 else 0 end) as Count_of_8,
                sum(case when switch_time2-switch_time1>(10*60) and switch_time2-switch_time1<(15*60) then 1 else 0 end as count_of_9,      ...
      FROM have
;
QUIT;

Upvotes: 1

Related Questions