Hello
I have numeric time field and I converted it into sas time field.
I want to create a new field called "ind_late_time' that is a binary variable that get value 1 if time is after 18:30 (06:30 PM) and value 0 otherwise.
What is the way to do it please?
Here is my try that got wrong results.
Data have;
Input time;
cards;
90200
0
181400
160300
113400
;
Run;
data have2;
set have;
time_=put(time,z6.);
time_new=input(time_,hhmmss6.);
Format time_new hhmm. ;
drop time_;
Run;
data want;
set have2;
IF time>='18:30:00't then Ind_late_time=1;
else Ind_late_time=0;
Run;
You create a variable time_new, but use the original time in your condition.
Simple enough. Since your existing variable is already numeric you can just store the actual time in seconds back into the same variable. Let's use a cutoff that some of the values actually exceed.
data have;
input time;
cards;
90200
0
181400
160300
113400
;
data want;
set have;
time=input(put(time,z6.),hhmmss6.);
format time tod5.;
Ind_late_time = time > '18:00:00't ;
run;
proc print;
run;
Ind_ late_ Obs time time 1 09:02 0 2 00:00 0 3 18:14 1 4 16:03 0 5 11:34 0
Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.
Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.
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.