BookmarkSubscribeRSS Feed
AAWTomHanks
Calcite | Level 5

Hi,

I am having trouble switching dates that look like this '28MAY1927:00:00:00' to '05/28/1927'. Does anyone know how to do this?

Thanks.

11 REPLIES 11
Tushar
Obsidian | Level 7


use anydtdte. format for reading date and once you read apply date9. format.

Tushar
Obsidian | Level 7

Please try below one...

data want;

  input date anydtdte.;

  format date date9.;

  cards;

28MAY1927:00:00:00

;

run;

Tushar
Obsidian | Level 7


One correction use date10. instead of date9.

Tushar
Obsidian | Level 7

Yesd KarlK you are right.. Thanks...

KarlK
Fluorite | Level 6

Tushar, I think you meant mmddyy10. format, no? The OP wants "05/28/1927", not "28MAY1927".

Karl

robertrao
Quartz | Level 8

Hi,

Cant we use datepart(date_time) and then use format on that?

Thanks

AAWTomHanks
Calcite | Level 5

Hi Guys,

Thanks for the help. One more question, what if it is a column I am using in a sas data table?

Thanks.

Tushar
Obsidian | Level 7

Suppose if its the sas dataset where on one variable you wanted to apply this format then you can use Proc dataset procedure with modify statement.

Ksharp
Super User

Make a format.

proc format;
picture x
 low-high='%0m/%0d/%Y'(datatype=datetime)     ;
run;
data want;
  input date datetime20.;
  x=date;
  format date datetime20. x x10.;
  cards;
28MAY1927:00:00:00
;
run;

Ksharp

robertrao
Quartz | Level 8


Hi Ksharp,

I have read the picture format after you have posted the solution and did not clearly understand it..

x  x10.; means u are applying a format named x10. on the variable x

what is the meaning of  '%0m/%0d/%Y' ?????

why did you put x  x10. ???? just x x. would not be enough???

Thanks

Ksharp
Super User

Plz check documentation firstly .

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
  • 11 replies
  • 1376 views
  • 3 likes
  • 5 in conversation