Published on :
Data Management INTERNAL_CREATION

SAS Date Management and Formatting

This code is also available in: Deutsch Español Français
Awaiting validation
This script illustrates how SAS© stores dates numerically (number of days since January 1, 1960). It creates a dataset containing a raw numeric value, a literal date, and the current date, then shows how to apply a format to make these values human-readable.
Data Analysis

Type : INTERNAL_CREATION


Data is dynamically generated in the Data step with no external dependency.

1 Code Block
DATA STEP Data
Explanation :
Creation of a 'date' table containing three variables: a numeric value representing a date (365 days after 01/01/1960), a SAS literal date, and the current date via the today() function.
Copied!
1/*
2Find the internal value for a given data in SAS.
3*/
4 
5DATA date;
6 date_numeric = 365;
7 date_literal = '02JAN1960'd;
8 today = today();
9RUN;
2 Code Block
PROC PRINT
Explanation :
Display of the content of the 'date' table. Dates will be displayed in their internal numeric form (number of days).
Copied!
1PROC PRINT DATA = date;
2RUN;
3 Code Block
DATA STEP Data
Explanation :
Creation of the 'date2' table from 'date'. Application of the 'mmddyy10.' format to the three date variables to display them in MM/DD/YYYY format.
Copied!
1* To format them;
2DATA date2;
3 SET date;
4 FORMAT date_literal date_numeric today mmddyy10.;
5RUN;
4 Code Block
PROC PRINT
Explanation :
Display of the 'date2' table with dates correctly formatted.
Copied!
1PROC PRINT DATA = date2;
2RUN;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.