BookmarkSubscribeRSS Feed
samHT
Calcite | Level 5

Hi ,

Please help in converting character variable (Start Date) to date format (mm/dd/yyyy). I have given an example below

Start date $

11/1/2009 0:00:00

4/2/2009 0:00:00

26/1/2009 0:00:00

26/11/2009 0:00:00

26/11/2009 12:00:00 AM

1/11/2009 0:00:00

1/11/2009 12:00:00 AM

Thank you for your help

1 REPLY 1
art297
Opal | Level 21

Here is one way:

options datestyle=dmy;

data have;

  informat Start_date $30.;

  input Start_date &;

  cards;

11/1/2009 0:00:00

4/2/2009 0:00:00

26/1/2009 0:00:00

26/11/2009 0:00:00

26/11/2009 12:00:00 AM

1/11/2009 0:00:00

1/11/2009 12:00:00 AM

;

data want (drop Start_date_in);

  set have (rename=(Start_date=Start_date_in));

  format Start_date mmddyy10.;

  Start_date=input(scan(Start_date_in,1,' ','r'), ddmmyy10.);

run;

I would have thought one could do it by inputting the entire datetime string, and using the anydtdtm informat, but it didn't work correctly for the 3rd from the last record.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 1349 views
  • 0 likes
  • 2 in conversation