BookmarkSubscribeRSS Feed
riya275
Obsidian | Level 7

I have variable with time with  values like 515 which should be read like 5:15 To do this I used the following code-

data flights;
set cs.flights;
format sched_dep_time hhmm. dep_time hhmm. ;
run;

but i get result for 515 as 0.09 which I think is the time it is calculating from 12:00 am in seconds . I also use time. format but no use. how do i deal with this?

5 REPLIES 5
Patrick
Opal | Level 21

@riya275

You will need to convert your number into a SAS Time value for this to work.

data test;
  timeAsNum=515;
  format timeAsSAS time5.;
  timeAsSAS=int(timeAsNum/100)*3600+mod(timeAsNum,100)*60;
run;
Patrick
Opal | Level 21

@riya275

Actually.... If you're just interested how your numeric variable prints but you don't need it to be a SAS Time value then a Picture format could serve the purpose as well.

proc format;
  picture numWithColon
    low-high = '00:00'
    ;
quit;

data test;
  format timeAsNum numWithColon4. timeAsSAS time5.;
  timeAsNum=515;

  timeAsSAS=int(timeAsNum/100)*3600+mod(timeAsNum,100)*60;
run;

 

Capture.JPG 

PGStats
Opal | Level 21

Try this:

 

data flights;
set cs.flights;
sched_dep_time_t = hms(int(sched_dep_time/100), mod(sched_dep_time, 100), 0);
dep_time_t = hms(int(dep_time/100), mod(dep_time, 100), 0);
format sched_dep_time_t dep_time_t hhmm. ;
drop sched_dep_time dep_time;
run;
PG
riya275
Obsidian | Level 7
No I want to calculate the difference between two time periods , so I need sas to identify this as a time variable to use intck function .
riya275
Obsidian | Level 7
Sorry I had to comment this the answer above , your answer seems easy and workable , I'll definitely try it . Thanks a lot !

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
  • 5 replies
  • 777 views
  • 1 like
  • 3 in conversation