DATA Step, Macro, Functions and more

Date Formats

Accepted Solution Solved
Reply
Super Contributor
Posts: 1,040
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,401

Re: Date Formats

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,401

Re: Date Formats

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,040

Re: Date Formats

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

Re: Date Formats

Typo, its not needed.

Super Contributor
Posts: 1,040

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: 683

Re: Date Formats

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
  • 321 views
  • 3 likes
  • 3 in conversation