BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
robertrao
Quartz | Level 8

 

 

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

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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

5 REPLIES 5
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;
robertrao
Quartz | Level 8
Hello,
Just wondering why is there a space before the hyphen when using compress function?
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Typo, its not needed.

robertrao
Quartz | Level 8
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
BrunoMueller
Meteorite | Level 14

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;

CFC_SAS_Communities_400x225.jpg

Call for content now open!

It's your turn to help shape SAS Innovate 2027. Share your expertise and inspire the SAS community.

Submit your proposal →

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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