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.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.