BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
kgot
Fluorite | Level 6

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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

5 REPLIES 5
Reeza
Super User

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

kgot
Fluorite | Level 6

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

Reeza
Super User

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;

kgot
Fluorite | Level 6

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?

kgot
Fluorite | Level 6

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!

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 1892 views
  • 3 likes
  • 2 in conversation