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