DATA Step, Macro, Functions and more

Date Formats

Accepted Solution Solved
Reply
Super Contributor
Posts: 1,041
Accepted Solution

Date Formats

 

 

Hello,

 

I have 4-Aug-2016 ($20.) , 05-Aug-2016 ($20.) and I want to convert it into a proper date foramt. The following does not work. Could someone suggest a proper method to do it?

 

data want;

set have;

Date2= input(Date,worddate.);

format Date2 date10.;

run;

 

Thanks


Accepted Solutions
Solution
‎10-24-2016 11:22 AM
Super User
Super User
Posts: 7,991

Re: Date Formats

Posted in reply to robertrao

One example:

data have;
  length dt $20;
  dt="4-Aug-2016"; output;
  dt="05-aug-2016"; output;
run;

data want;
  set have;
  d2=input(compress(dt," -"),date9.);
  format d2 date9.;
run;

View solution in original post


All Replies
Solution
‎10-24-2016 11:22 AM
Super User
Super User
Posts: 7,991

Re: Date Formats

Posted in reply to robertrao

One example:

data have;
  length dt $20;
  dt="4-Aug-2016"; output;
  dt="05-aug-2016"; output;
run;

data want;
  set have;
  d2=input(compress(dt," -"),date9.);
  format d2 date9.;
run;
Super Contributor
Posts: 1,041

Re: Date Formats

Hello,
Just wondering why is there a space before the hyphen when using compress function?
Super User
Super User
Posts: 7,991

Re: Date Formats

Posted in reply to robertrao

Typo, its not needed.

Super Contributor
Posts: 1,041

Re: Date Formats

First I thought the space is used to let SAS to keep anything before that but then I removed the space and still it worked. Just double checking. Thank you again
SAS Super FREQ
Posts: 709

Re: Date Formats

Posted in reply to robertrao

The answer is already solved, just wanted to mention, that the date11 informat can read the dates that are shown.

 

See sample code below:

data have;
  length dt $20;
  dt="4-Aug-2016"; output;
  dt="05-aug-2016"; output;
run;

data want;
  set have;
  d2 = input(dt, date11.);
  format d2 date9.;
run;
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 324 views
  • 3 likes
  • 3 in conversation