BookmarkSubscribeRSS Feed
Gil_
Quartz | Level 8
Hi I have a datetime field open date
08/01/2017 1;42;00 PM
I need to convert the date to
08/01/2017 13:42 PM

Thanks
5 REPLIES 5
Shmuel
Garnet | Level 18

Change format from DATEAMPMw.  to DATETIMEw. where w is length of output dislaying date and time.

 

If time is 13:42 there is no need to add PM.

Gil_
Quartz | Level 8
Hi Shmuel.
Thanks for response...how do I apply it I'm using a
Data table1;
Set table1;
Time =timepart (open _date);
Format time datetime.;
Run;

It gives 01jan1960 05:49:53 the time is still at general time
Shmuel
Garnet | Level 18

When you use function TIMEPART you have time only, without the date.

 

format DATETIME is to be used with your variable Open_Date.

 

Use format time5. or time7. for TIME (as timepart).

Data table1;
Set table1;
Time =timepart (open _date);
Format open_date datetime. 
            time    time7.;
Run;

Look at next link - formats by categories:

http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a001263753.htm

 

 

Gil_
Quartz | Level 8
Thanks for the example it did 2 things it convert all my dates to 01jan6005:49:53. So the column of time it does give me the right format but the time is 5:49:53 should be 04:49:53 .. I'm using your data set .. thanks
Shmuel
Garnet | Level 18

You compute 

Time =timepart (open_date);

which gives you a date of 01jan60 - this turns a red light, maybe your variable Open_Date is not a datetime but a time only.

In sas 0 (zero) is equal to Jan 1st 1960.

 

Try do:

Data _NULL_;
set have;
 put open_date  time9.;
run;

and check the log.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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