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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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