file 1 dob1 and dob2 look like:
5/13/1980 7/3/1970
and it is character
file 2 dob1 and dob2 look like:
19590920 19700813
and it is numeric
how do i convert file 2 dates to match file 1 dates' format?
Both files conbtain incorrect formats for SAS dates. So I wouldn't show you have to convert from one incorrect format to a different incorrect format. But I will show you how to convert both files so they hold valid SAS dates.
For the first file, converting from character "dates":
data new_file_1;
set file1;
correct_dob1 = input(dob1 mmddyy10.);
correct_dob2 = input(dob2, mmddyy10.);
drop dob1 dob2;
format correct_dob1 correct_dob2 mmddyy10.;
run;
For the second file, converting from numeric "dates":
data correct_file2;
set file2;
correct_dob1 = input(put(dob1, z8.), yymmdd8.);
correct_dob2 = input(put(dob2, z8.), yymmdd8.);
drop dob1 dob2;
format correct_dob1 correct_dob2 mmddyy10.;
run;
There's a ton of information within the SAS documentation about how to store SAS dates. Here's a starting point: https://documentation.sas.com/doc/en/lrcon/9.4/p1wj0wt2ebe2a0n1lv4lem9hdc0v.htm
Please show us the full log (as requested by @Reeza ) and also PROC CONTENTS output on these two data sets.
@bhca60 ,
The requests you have received are all the right questions. Don't just tell us what happened, show us. These are all excellent programmers. If any of them encountered the messages you have received, they would all debug using the same tools: the log (including not just the error message, but the line of code that generated the message) and a PROC CONTENTS of the underlying data.
file 1 dob1 and dob2 look like:
5/13/1980 7/3/1970
and it is character
Assuming you meant that you have a SAS dataset, say it is named HAVE1, with two characters variables named DOB1 and DOB2 with strings like '5/13/1980' and '7/3/1970':
Then you can create new variables that have actual DATE values by using the INPUT() function.
data have1_fixed;
set have1;
date1 = input(left(dob1),mmddyy10.);
date2 = input(left(dob2),mmddyy10.);
format date1 date2 date9.;
run;
The second one is harder:
file 2 dob1 and dob2 look like:
19590920 19700813
and it is numeric
Because you do not say what FORMAT (if any) is attached to those two variables. If it has the format YYMMDDN8 attached then the values are already DATES and no conversion is needed.
But if there is no format attach or perhaps the format 8. or BEST12. is attached then the variables do NOT have date values. Instead they just have numbers like 19,590,920 and 19,700,813 that only look to humans like they might be dates if you print them without the thousands separators.
To fix those you will need to first convert the numbers into strings so you can again use the INPUT() function, only this time with the YYMMDD informat.
data have2_fixed;
set have2;
date1 = input(put(dob1,Z8.),yymmdd10.);
date2 = input(put(dob2,Z8.),yymmdd10.);
format date1 date2 date9.;
run;
Not if you want to combine them you will have to drop (or rename) one or both pairs of original variables since DOB1 cannot be both a character string and a numeric variable at the same time.
data want;
set have1_fixed(rename=(dob1=dob1_char dob2=dob2_char))
have2_fixed
;
run;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.