BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
femiajumobi1
Quartz | Level 8

I am trying to format the date in a dataset.

 

 examples in the column for date are: 21658, 31193

I have used different approaches (e.g., date9., MMDDYY10. ) but unable to format the date

Please advise. The date appears as such using proc contents:

#

Variable

Type

Len

Format

Informat

Label

2

birth_date

Char

25

$25.

$25.

birth_date

 
1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

Variable birth_date is a character variable.  Dates in SAS must be numeric. You have to create a numeric variable with that value and then format the numeric variable. In this case, the values like 21658 and 31193 may be recognizable by SAS as dates, or they may have come over from Excel in which case additional manipulation is needed.

 

data want;
    set have;
    num_birth_date=input(birth_date,12.);
    format num_birth_date mmddyy10.;
run;

 

Side issue: if at all possible, avoid storing dates as characters. Store them in numeric SAS variables, in a form that SAS will recognize, which is the number of days since 01JAN1960, formatted however you want.

--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

Variable birth_date is a character variable.  Dates in SAS must be numeric. You have to create a numeric variable with that value and then format the numeric variable. In this case, the values like 21658 and 31193 may be recognizable by SAS as dates, or they may have come over from Excel in which case additional manipulation is needed.

 

data want;
    set have;
    num_birth_date=input(birth_date,12.);
    format num_birth_date mmddyy10.;
run;

 

Side issue: if at all possible, avoid storing dates as characters. Store them in numeric SAS variables, in a form that SAS will recognize, which is the number of days since 01JAN1960, formatted however you want.

--
Paige Miller
femiajumobi1
Quartz | Level 8
Thanks @PaigeMiller

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 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 3583 views
  • 0 likes
  • 2 in conversation