How do I convert time variable to display with AM/PM?

Reply
Occasional Contributor eap
Occasional Contributor
Posts: 11

How do I convert time variable to display with AM/PM?

I imported an Excel file (.xlsx) into SAS 9.4 that contains a time variable.

 

I think I need to do something in a Data Step but I get confused with the time informat versus the time format and can't figure out how to use TIMEAMPM.

 

The time variable is in this format in Excel. I want to display time like this as well in the SAS output.

 

This is as far as I got which I know is wrong. Help please!

'Incid_time' variable in Excel converts to this in SAS before attempting to do any manipulation.
9:23 PM converts to 0.414583333 11:36 AM converts to 0.940972222 1:33 AM converts to 0.6111111 2:23 AM converts to 0.34444444 DATA TC_viaEMS; SET viaEMS_2013 viaEMS_2014 ; incid_timeN =input(incid_time, time7.); format incid_timeN TIMEAMPM7.; run;
NOTE 484-185: Format $TIMEAMPM was not found or could not be loaded.

 

 



Super User
Posts: 17,818

Re: How do I convert time variable to display with AM/PM?

Try applying the time format directly to the incide_time variable. 

Trusted Advisor
Posts: 1,374

Re: How do I convert time variable to display with AM/PM?

[ Edited ]

Use TIMEAMPMw.d format.

 

If need calculate _time = timepart(_datetime)

Occasional Contributor eap
Occasional Contributor
Posts: 11

Re: How do I convert time variable to display with AM/PM?

Thanks for the suggestion. However, I tried it and still got an error. So I decided to I close SAS, reopened it, and re-ran the original program – and it finally worked.

Ask a Question
Discussion stats
  • 3 replies
  • 270 views
  • 0 likes
  • 3 in conversation