To format a date variable in SAS like yyyy-mm-dd, you can use the yymmdd10. date format in a data step.

data example;
    d = "15sep2022"d;
    put d yymmdd10.;
run;

// Log Output:
2022-09-15

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 the yymmdd10. date format.

Below shows a simple example of formatting a date like yyyy-mm-dd with yymmdd10. in a SAS data step.

data example;
    d = "15sep2022"d;
    put d yymmdd10.;
run;

// Log Output:
2022-09-15

Other Date Formats in SAS

There are a number of other date formats you can use in SAS to format date variables.

A common date format which is commonly used in real world applications is showing the month and year of a date.

To format a date like month and year in SAS, you can use the monyyw. date format. The two valid formats for month and year are the monyy5. or monyy7. date formats.

Below shows you how to format a date with the monyy5. or monyy7. date formats in SAS.

data example;
    d = "15sep2022"d;
    put d monyy5.;
    put d monyy7.;
run;

// Log Output:
SEP22
SEP2022

Another common date format which is commonly used in real world applications is showing a date like ddmmmyyyy.

To format a date like month and year in SAS, you can use the datew. date format. To get a date like ddmmmyyyy, you can use date9.

Below shows you how to format a date with the date9. date format in SAS.

data example;
    d = "15sep2022"d;
    put d date9.;
run;

// Log Output:
15SEP2022

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.

Categorized in:

SAS,

Last Update: March 11, 2024