## How to convert dates

Solved
Frequent Contributor
Posts: 76

# How to convert dates

I have dates in two different format. One is 19861031 (YYMMDDN8). and the other  31Oct1986 (DATE9). Can somebody tell me how to make the two dates comparable and in the same format.

Accepted Solutions
Solution
‎01-10-2018 07:53 PM
PROC Star
Posts: 1,400

## Re: How to convert dates

Assumed that the two variables are actually sas date values (Formatted numeric values), then they are already comparable in the sense that you can compare them with comparison operators in SAS.

You can make the two dates the same format with a simple format statement like this

``````data have;
input date1:yymmdd10. date2:date9.;
format date1 yymmdd10. date2 date9.;
datalines;
19861031 31Oct1986
;

data want;
set have;
format date1 date9.;
run;``````

All Replies
Super User
Posts: 23,958

## Re: How to convert dates

[ Edited ]

Are they different variables or the same variable? What is the type and format of each variable? What are you trying to do with them that makes you think they can't be compared as is.

Agent1592 wrote:

I have dates in two different format. One is 19861031 (YYMMDDN8). and the other  31Oct1986 (DATE9). Can somebody tell me how to make the two dates comparable and in the same format.

Super User
Posts: 2,496

## Re: How to convert dates

The dates are already comparable. Since you say that they have date formats, they are SAS dates.

Just use the format statement to change their format.

Solution
‎01-10-2018 07:53 PM
PROC Star
Posts: 1,400

## Re: How to convert dates

Assumed that the two variables are actually sas date values (Formatted numeric values), then they are already comparable in the sense that you can compare them with comparison operators in SAS.

You can make the two dates the same format with a simple format statement like this

``````data have;
input date1:yymmdd10. date2:date9.;
format date1 yymmdd10. date2 date9.;
datalines;
19861031 31Oct1986
;

data want;
set have;
format date1 date9.;
run;``````
☑ This topic is solved.