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.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1565 views
  • 0 likes
  • 2 in conversation