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: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 4 replies
  • 566 views
  • 0 likes
  • 5 in conversation