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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

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;

View solution in original post

3 REPLIES 3
Reeza
Super User

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.


 

ChrisNZ
Tourmaline | Level 20

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.

PeterClemmensen
Tourmaline | Level 20

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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 722 views
  • 1 like
  • 4 in conversation