For example: I have the original DOB as '01JAN2020'. I would like to convert it to '01/01/2020'
Do you mean you have a character variable DOB which appears as 01JAN2020?
num_date=input(dob,date9.);
format num_date ddmmyys10.;
Or do you mean you have a numeric variable that displays as 01JAN2020?
format dob ddmmyys10.;
It seems that your DOB is already a SAS date variable, with a DATE9. format. If that is the case, just change the format to MMDDYY10. or DDMMYY10. (depending on which order you want displayed).
@takpdpb7 wrote:
For example: I have the original DOB as '01JAN2020'. I would like to convert it to '01/01/2020'
Do you have a character variable or a numeric variable? (SAS only has two types.)
If you have a numeric variable change the format attached to have it displayed in the different way.
format dob mmddyy10.;
If you have a character variable then convert it to a date value first.
dob = put( input(dob,date9.) , mmddyy10.);
Note: I assumed that the first 01 is the MONTH. Others might assume it is DAY. That is why you should use either DATE9. or YYMMDD10. format instead of MMDDYY10. or DDMMYY10. to avoid that confusion.
data have;
sas_date = '01JAN2020'd;
dob = sas_date;
dob2 = sas_date;
format dob date9.
dob2 mmddyys10.;
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.