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;

Ready to join fellow brilliant minds for the SAS Hackathon?

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!
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
  • 488 views
  • 0 likes
  • 5 in conversation