- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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 |
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content