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 |
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.
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.
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
For SAS newbies, this video is a great way to get started. James Harroun walks through the process using SAS Studio for SAS OnDemand for Academics, but the same steps apply to any analytics project.
Find more tutorials on the SAS Users YouTube channel.