BookmarkSubscribeRSS Feed
Ronein
Meteorite | Level 14

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

 

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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