Convert character variable to a new variable with date format

Accepted Solution Solved
Reply
Occasional Contributor MCB
Occasional Contributor
Posts: 15
Accepted Solution

Convert character variable to a new variable with date format

Hi,

I would like to convert the character variable 01Jan2006 (the format and informat is $9.) into a date format that should look like this: 2006-01-01.

I tried some syntax but I did not succeed.

Thank you!

/Marcela


Accepted Solutions
Solution
‎05-08-2014 02:46 PM
Trusted Advisor
Posts: 1,204

Re: Convert character variable to a new variable with date format

Try this one.

data have;

dt="01Jan2006";

dt_new=input(dt,date9.);

format dt_new yymmdd10.;

run;

proc print data=have;

run;

View solution in original post


All Replies
Super User
Posts: 17,784

Re: Convert character variable to a new variable with date format

What did you try?

Occasional Contributor MCB
Occasional Contributor
Posts: 15

Re: Convert character variable to a new variable with date format

At the moment I don't have access to my files and code so I am not sure



Occasional Contributor MCB
Occasional Contributor
Posts: 15

Re: Convert character variable to a new variable with date format

I tried something like this:

data Old;

infile cards;

informat date $9.;

input Olddate ;

cards;

01Jan2006

05Feb2009

;

data New;

set Old;

format  newdate yymmdd10.;

newdate=input(trim(olddate),yymmdd10.);

run;

Solution
‎05-08-2014 02:46 PM
Trusted Advisor
Posts: 1,204

Re: Convert character variable to a new variable with date format

Try this one.

data have;

dt="01Jan2006";

dt_new=input(dt,date9.);

format dt_new yymmdd10.;

run;

proc print data=have;

run;

Occasional Contributor MCB
Occasional Contributor
Posts: 15

Re: Convert character variable to a new variable with date format

Tank you!

this was very helpful!!

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 694 views
  • 1 like
  • 3 in conversation