Help using Base SAS procedures

Change a Dates Format

Reply
Contributor
Posts: 37

Change a Dates Format

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.

Frequent Contributor
Posts: 88

Re: Change a Dates Format


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

Frequent Contributor
Posts: 88

Re: Change a Dates Format

Please try below one...

data want;

  input date anydtdte.;

  format date date9.;

  cards;

28MAY1927:00:00:00

;

run;

Frequent Contributor
Posts: 88

Re: Change a Dates Format


One correction use date10. instead of date9.

Frequent Contributor
Posts: 88

Re: Change a Dates Format

Yesd KarlK you are right.. Thanks...

Contributor
Posts: 65

Re: Change a Dates Format

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

Karl

Super Contributor
Posts: 1,040

Re: Change a Dates Format

Hi,

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

Thanks

Contributor
Posts: 37

Re: Change a Dates Format

Hi Guys,

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

Thanks.

Frequent Contributor
Posts: 88

Re: Change a Dates Format

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.

Super User
Posts: 9,681

Re: Change a Dates Format

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

Super Contributor
Posts: 1,040

Re: Change a Dates Format


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

Super User
Posts: 9,681

Re: Change a Dates Format

Plz check documentation firstly .

Ask a Question
Discussion stats
  • 11 replies
  • 271 views
  • 3 likes
  • 5 in conversation