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.
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;
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.
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.
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;
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!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.