BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Geo-
Quartz | Level 8

Hi,I got a table and there is a column "switch_time" and looks like:

switch_time
8:00:15
9:12:13
18:20:36

 

I want to use :

 

PROC SQL;
   CREATE TABLE MC_ET AS
   SELECT 
                sum(case when switch_time between "8:00:00" and "9:00:00" then 1 else 0 end) as Count_of_8,
                sum(case when switch_time between "9:00:00" and "10:00:00" then 1 else 0 end) as count_of_9,
... FROM have ; QUIT;
1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26
proc sql;
   create table mc_et as
   select sum(case when switch_time between "8:00"t and "9:00"t then 1 else 0 end) as count_of_8,
          sum(case when switch_time between "9:00"t and "10:00"t then 1 else 0 end) as count_of_9,
...
from have; quit;

You should be able to use time literals (indicated by the t after the string), assuming switch_time is numeric, or you can use the input() function around each time.  Please avoid coding in shouting case.

View solution in original post

1 REPLY 1
RW9
Diamond | Level 26 RW9
Diamond | Level 26
proc sql;
   create table mc_et as
   select sum(case when switch_time between "8:00"t and "9:00"t then 1 else 0 end) as count_of_8,
          sum(case when switch_time between "9:00"t and "10:00"t then 1 else 0 end) as count_of_9,
...
from have; quit;

You should be able to use time literals (indicated by the t after the string), assuming switch_time is numeric, or you can use the input() function around each time.  Please avoid coding in shouting case.

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
  • 1 reply
  • 863 views
  • 0 likes
  • 2 in conversation