• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Programming Expert

Solving All of Your Programming Headaches

  • HTML
  • JavaScript
  • jQuery
  • PHP
  • Python
  • SAS
  • Ruby
  • About
You are here: Home / SAS / yyyy-mm-dd Date Format in SAS

yyyy-mm-dd Date Format in SAS

September 15, 2022 Leave a Comment

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.

Other Articles You'll Also Like:

  • 1.  SAS compress – Remove Whitespace and Characters from String
  • 2.  SAS %eval() Function – Evaluate Expressions in SAS Macro
  • 3.  SAS Delete Dataset – Use PROC Datasets to Delete SAS Files
  • 4.  SAS where in – Subset Data by Multiple Values in Data Step
  • 5.  Identifying Duplicates in SAS with PROC SORT dupout Option
  • 6.  Set Multiple Datasets in SAS Data Step
  • 7.  mod Function in SAS – Find Remainder of 2 Numbers After Division
  • 8.  SAS sum() Function – Find Sum Across Columns in Data Step
  • 9.  How to Select First 100 Observations of SAS Dataset
  • 10.  SAS trim – Remove All Trailing Blanks from String Variable in Data Step

About The Programming Expert

The Programming Expert is a compilation of a programmer’s findings in the world of software development, website creation, and automation of processes.

Programming allows us to create amazing applications which make our work more efficient, repeatable and accurate.

At the end of the day, we want to be able to just push a button and let the code do it’s magic.

You can read more about us on our about page.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

About The Programming Expert

the programming expert main image

Welcome to The Programming Expert. We are a group of US-based programming professionals who have helped companies build, maintain, and improve everything from simple websites to large-scale projects.

We built The Programming Expert to help you solve your programming problems with useful coding methods and functions in various programming languages.

Search

Learn Coding from Experts on Udemy

Looking to boost your skills and learn how to become a programming expert?

Check out the links below to view Udemy courses for learning to program in the following languages:

Copyright © 2023 · The Programming Expert · About · Privacy Policy