Creating a SAS Date from Month, Day, and Year - SAS Programming

Suppose you have a data file containing dates in a format for which SAS software does not have an informat.Suppose further that you can extract the month, day, and year of each date.To make it still more gruesome,suppose that the month, day, and year information are not even in contiguous columns. Enter the MDY function.

This function,which takes as its arguments month, day, and year, will create a SAS date for you. For example, suppose you have DAY in columns 1-2, MONTH in columns 10-11,and YEAR in columns 20-23.To create a SAS date, you would code:

Example

DATA MDYEXAMP;
INPUT DAY 1-2
MONTH 10-11
YEAR 20-23;
DATE=MDY (MONTH,DAY,YEAR);
FORMAT DATE WORDDATE*;
DATAMNES;
12 11 1992
11 09 1899
;
PROC PRINT DATA=MDYEXAMP;
TITLE 'Example of MDY function';
RUN;

Output from Example - Creating a SAS Date from Month, Day, and Year

Output from Example - Creating a SAS Date from Month, Day, and Year

The WORDDATE format prints the month name,the day of the month, and the year as seen in the above output.


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

SAS Programming Topics