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

In an existing dataset, is there a way to change a column of dates in the format of "mm/dd/yyyy" to character format of "mmddyyyy"?  thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
Linlin
Lapis Lazuli | Level 10

data have;

informat date mmddyy10.;

format date mmddyy10.;

input date;

cards;

01/31/2012

;

data want;

set have;

ndate=put(date,mmddyyn.);

proc print;run;

or

data want;

set have(rename=date=ndate) ;

date=put(ndate,mmddyyn.);

drop ndate;

proc print;run;

Obs      date

1     01312012

View solution in original post

7 REPLIES 7
Linlin
Lapis Lazuli | Level 10

data have;

informat date mmddyy10.;

format date mmddyy10.;

input date;

cards;

01/31/2012

;

data want;

set have;

ndate=put(date,mmddyyn.);

proc print;run;

or

data want;

set have(rename=date=ndate) ;

date=put(ndate,mmddyyn.);

drop ndate;

proc print;run;

Obs      date

1     01312012

Cyndia
Calcite | Level 5

Linlin, thanks!   it's perfect.

Cyndia
Calcite | Level 5

the date converted mmddyyyyy seems to be still numeric.  is there a way to change it to Character mmddyyyy ?

i tried

ndob=put(dob, $8.);

the ndob became negative number that does not look like a date any more.

Haikuo
Onyx | Level 15

Please post the complete code that you have run. LinLin' code meets your requirement.

Haikuo

Cyndia
Calcite | Level 5

data xyz2;

set xyz1;

format olddate mmddyyn.;

run;


/*Now the olddate changed from mm/dd/yyyy to mmddyyyy in new dataset xyz2

but the variable type is still numeric.

the question is how to change the mmddyyyy to character type? */

/* i tried the following to change oldate to a new column named newdate and change it to character type, but newdate became negative value that does not look like a date but a number only.  how to make mmddyyyy from numeric to characters mmddyyyy?   */

newdate=put(olddate, $8.);

Haikuo
Onyx | Level 15

Try this, btw, LinLin already has this in her code:

newdate=put(olddate, mmddyyn.);

The first format you used is just a format change, not a type change, so olddate will still be the way it is, numeric. You need to involve a new variable ( you have tried) to fix this.

Haikuo

Cyndia
Calcite | Level 5

the following works:

data xyz2;

set xyz1;

newdate=put(olddate, mmddyyn.);

run;

thanks.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to choose a machine learning algorithm

Use this tutorial as a handy guide to weigh the pros and cons of these commonly used machine learning algorithms.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 7 replies
  • 21585 views
  • 4 likes
  • 3 in conversation