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.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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