Help using Base SAS procedures

Difficulty with SAS time format

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 11
Accepted Solution

Difficulty with SAS time format

I am not sure what's going on, but I keep trying to convert seconds to time5, and it is not working.

I am first reading a datetime field from an Oracle passthrough, then taking the timepart, and trying to get it to format as a time5. (For example, I WANT it to display as 23:00 in a report later on, but it is instead displaying as 82800.) However, the time keeps displaying as seconds in the final document. What am I missing in the code?

Here is what I have:

data time_out;

  set time_in;

  time_fld=timepart(time_fld1);

run;

proc datasets library=work;

  modify time_out;

  format time_fld time5.;

run;

I have also tried running the time5 format directly in the data step, but it still is displaying the seconds.

Thank you!


Accepted Solutions
Solution
‎08-27-2015 04:07 PM
Super User
Posts: 17,819

Re: Difficulty with SAS time format

I think if there is an issue it's a part of the code you're not showing.

Does the following base case work for you?

data have;

datetime=datetime();

format date: datetime21.;

run;

proc print; run;

data want;

set have;

time=timepart(datetime);

format time time5.;

run;

proc print; run;

ods tagsets.excelxp file="C:\_localdata\delete.xml" style=meadow;

proc print data=want;

run;

ods tagsets.excelxp close;

View solution in original post


All Replies
Super User
Posts: 17,819

Re: Difficulty with SAS time format

What is the final document and how does it get there?

Occasional Contributor
Posts: 11

Re: Difficulty with SAS time format

It is an Excel file that is put together via an ods tagsets.excelxp.

Solution
‎08-27-2015 04:07 PM
Super User
Posts: 17,819

Re: Difficulty with SAS time format

I think if there is an issue it's a part of the code you're not showing.

Does the following base case work for you?

data have;

datetime=datetime();

format date: datetime21.;

run;

proc print; run;

data want;

set have;

time=timepart(datetime);

format time time5.;

run;

proc print; run;

ods tagsets.excelxp file="C:\_localdata\delete.xml" style=meadow;

proc print data=want;

run;

ods tagsets.excelxp close;

Occasional Contributor
Posts: 11

Re: Difficulty with SAS time format

Yes, that did display correctly:

127AUG2015:16:11:0516:11

As far as I can tell, I don't do any further processing to this particular dataset later on, except to join it up to other tables and output this time field. Is there anything else I should look for to troubleshoot?

Occasional Contributor
Posts: 11

Re: Difficulty with SAS time format

ACTUALLY, your comment on it being somewhere else in the code made me look elsewhere. I had this data joining to another table in a proc sql, and it must have been reverting back to the seconds then. I put a format in the proc sql, and it worked. Thank you, Reeza!

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 388 views
  • 3 likes
  • 2 in conversation