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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 235 views
  • 2 likes
  • 3 in conversation