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 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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