To format a date with the yymmdd10 format in SAS, you can format a date variable like ‘YYYY-MM-DD’.
data example;
d = "14sep2022"d;
put d yymmdd10.;
run;
// Log Output:
2022-09-14
If you want to format a date like ‘YYYY/MM/DD” then you can use yymmdds10 in a data step.
data example;
d = "14sep2022"d;
put d yymmdd10s.;
run;
// Log Output:
2022/09/14
When working with different variables in SAS, the ability to change formats easily is valuable.
One such case is if you have a date and want to format it differently.
A date format which is commonly used in real world applications is “YYYY-MM-DD”. This date format shows the full year, the month number and date separated by hyphens.
The SAS date format to get this date format is yymmdd10.
Below shows a simple example of formatting a date with yymmdd10. in a SAS data step.
data example;
d = "14sep2022"d;
put d yymmdd10.;
run;
// Log Output:
2022-09-14
If you want to format a date like ‘YYYY/MM/DD” then you can use yymmdds10. in a Data Step.
data example;
d = "14sep2022"d;
put d yymmdd10s.;
run;
// Log Output:
2022/09/14
Other Date Formats in SAS
There are a number of other date formats you can use in SAS to format date variables.
Below show you a bunch of different date formats and the resulting output in a SAS data step.
data example;
d = "14sep2022"d;
put d yymmdd2.;
put d yymmdd3.;
put d yymmdd4.;
put d yymmdd5.;
put d yymmdd6.;
put d yymmdd7.;
put d yymmdd8.;
put d yymmdd10.;
put d yyq.;
put d yyq4.;
put d yyq5.;
put d yyq6.;
put d yyq10.;
run;
// Log Output:
22
22
2209
22-09
220914
220914
22-09-14
2022-09-14
2022Q3
22Q3
22Q3
2022Q3
2022Q3
Hopefully this article has been useful for you to learn how to use the SAS YYMMDD10 date format for formatting dates in SAS data steps.