Table of Contents
To convert a numeric variable into a date using the SAS software, you can use the INPUT function. This function allows you to specify the format of the input variable and convert it into a date format. You can also use the DATE informat to directly read a numeric variable as a date. Additionally, you can use the PUT function to convert a numeric variable into a specific date format. It is important to ensure that the numeric variable is in the correct format before performing any conversion. By utilizing these functions, you can easily convert a numeric variable into a date in SAS.
SAS: Convert Numeric Variable to Date
You can use the following basic syntax to convert a numeric variable to a date variable in SAS:
date_var = input(put(numeric_var, 8.), MMDDYY10.);
format date_var MMDDYY10.;The following example shows how to use this function in practice.
Related:
Example: Convert Numeric Variable to Date in SAS
Suppose we have the following dataset in SAS that shows the total sales made by some store during various different days:
/*create dataset*/ data original_data; input day sales; datalines; 01012022 15 01022022 19 01052022 22 01142022 11 01152022 26 01212022 28 ; run; /*view dataset*/ proc printdata=original_data;

We can use proc contents to view the data type of each variable in the dataset:
/*display data type for each variable*/
proc contentsdata=original_data;

We can see that day and sales are both numeric variables.
We can use the following code to create a new dataset in which we convert the day variable from numeric to date:
/*create new dataset where 'day' is date*/
data new_data;
set original_data;
date_day = input(put(day, 8.), MMDDYY10.);
format date_day MMDDYY10.;
drop day;
run;
/*view new dataset*/
proc printdata=new_data; 
Note: We used the drop function to drop the original day variable from the dataset.
We can see that the new variable we created, date_day, is in a date format.
The following tutorials explain how to perform other common tasks in SAS:
Cite this article
stats writer (2024). How can I convert a numeric variable into a date using the SAS software?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-can-i-convert-a-numeric-variable-into-a-date-using-the-sas-software/
stats writer. "How can I convert a numeric variable into a date using the SAS software?." PSYCHOLOGICAL SCALES, 26 Jun. 2024, https://scales.arabpsychology.com/stats/how-can-i-convert-a-numeric-variable-into-a-date-using-the-sas-software/.
stats writer. "How can I convert a numeric variable into a date using the SAS software?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-can-i-convert-a-numeric-variable-into-a-date-using-the-sas-software/.
stats writer (2024) 'How can I convert a numeric variable into a date using the SAS software?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-can-i-convert-a-numeric-variable-into-a-date-using-the-sas-software/.
[1] stats writer, "How can I convert a numeric variable into a date using the SAS software?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, June, 2024.
stats writer. How can I convert a numeric variable into a date using the SAS software?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.
