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!
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;
What is the final document and how does it get there?
It is an Excel file that is put together via an ods tagsets.excelxp.
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;
Yes, that did display correctly:
1 | 27AUG2015:16:11:05 | 16: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?
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!
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.
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.
Ready to level-up your skills? Choose your own adventure.