Contributor
Posts: 23

# Read time value in SAS of the form 515 as 5:15

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?

Posts: 4,687

## Re: Read time value in SAS of the form 515 as 5:15

@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;
``````
Posts: 4,687

## Re: Read time value in SAS of the form 515 as 5:15

[ Edited ]

@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;``````

Posts: 5,482

## Re: Read time value in SAS of the form 515 as 5:15

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
Contributor
Posts: 23

## Re: Read time value in SAS of the form 515 as 5:15

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 .
Contributor
Posts: 23

## Re: Read time value in SAS of the form 515 as 5:15

Sorry I had to comment this the answer above , your answer seems easy and workable , I'll definitely try it . Thanks a lot !
Discussion stats
• 5 replies
• 304 views
• 1 like
• 3 in conversation