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 .

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 11 replies
  • 3030 views
  • 3 likes
  • 5 in conversation