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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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