turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- General Programming
- /
- Read time value in SAS of the form 515 as 5:15

Topic Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

09-10-2017 05:52 AM

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?

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to riya275

09-10-2017 06:59 AM

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

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to riya275

09-10-2017 07:06 AM - edited 09-10-2017 07:08 AM

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

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to riya275

09-10-2017 08:44 PM

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

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to riya275

09-10-2017 11:18 PM

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 .

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to riya275

09-10-2017 11:22 PM

Sorry I had to comment this the answer above , your answer seems easy and workable , I'll definitely try it . Thanks a lot !