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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.