BookmarkSubscribeRSS Feed
takpdpb7
Calcite | Level 5

For example: I have the original DOB as '01JAN2020'. I would like to convert it to '01/01/2020'

4 REPLIES 4
PaigeMiller
Diamond | Level 26

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

 

--
Paige Miller
Kurt_Bremser
Super User

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).

Tom
Super User Tom
Super User

@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.

mklangley
Lapis Lazuli | Level 10
data have;
    sas_date = '01JAN2020'd;
    dob = sas_date;
    dob2 = sas_date;
    format dob date9.
           dob2 mmddyys10.;
run;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 646 views
  • 0 likes
  • 5 in conversation