SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

How to convert character format yyyymmdd to a date format ?

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 10
Accepted Solution

How to convert character format yyyymmdd to a date format ?


I have one variable 'birthd' that shows value in character format (e.g. 19890629). I want to convert that into a date variable mmddyy in the same file work.test.

Attached is the below code - the variable date_new shows up as numeric instead of date format.

Much help appreciated.

Thanks,

Neil.

WORK.merged;

WORK.merged_COPY;

date_new = input(birthd, yymmdd8.);

format date_new date10.;

run;


Accepted Solutions
Solution
‎01-06-2014 04:31 PM
Respected Advisor
Posts: 4,173

Re: How to convert character format yyyymmdd to a date format ?

It works for me.

A SAS date value gets stored in a numeric variable as number of days since 01Jan1960 with a format attached.

data test;

  birthd='19890629';

  date_new = input(birthd, yymmdd8.);

  format date_new date10.;

run;

View solution in original post


All Replies
Solution
‎01-06-2014 04:31 PM
Respected Advisor
Posts: 4,173

Re: How to convert character format yyyymmdd to a date format ?

It works for me.

A SAS date value gets stored in a numeric variable as number of days since 01Jan1960 with a format attached.

data test;

  birthd='19890629';

  date_new = input(birthd, yymmdd8.);

  format date_new date10.;

run;

Super User
Posts: 19,770

Re: How to convert character format yyyymmdd to a date format ?

What do you mean by numeric rather than date format?

SAS has only two variable types, numbers and characters and a "date" variable is a number with a date format, specifically the number of days from Jan 1, 1960.

Super User
Super User
Posts: 7,039

Re: How to convert character format yyyymmdd to a date format ?

If you want the dates to display in month,day, year format then use a format that will do that.  For example for today (06JAN2014)  to display as 06012014 you would use:

format date_new mmddyyn8.;

🔒 This topic is solved and locked.

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

Discussion stats
  • 3 replies
  • 93660 views
  • 8 likes
  • 4 in conversation