BookmarkSubscribeRSS Feed
Ronein
Onyx | Level 15

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;
2 REPLIES 2
Tom
Super User Tom
Super User

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

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1036 views
  • 2 likes
  • 3 in conversation