This tutorial focuses on converting a number format variable to a date format variable.
Sample Data
Solution
Explanation
![]() |
Convert Number Format to Date Format |
Suppose you have a numeric variable that contains dates. You are asked to convert it to SAS date format. It seems to be a easy task but it sometimes becomes a daunting task when you don't know how SAS treats dates. The input data is shown below -
![]() |
Raw Date Values |
The following program is used to create a sample data.
data temp;
input date;
cards;
20160514
19990505
20131104
20110724
;
run;
data temp2;
set temp;
newdate = input(put(date,8.),yymmdd8.);
format newdate date10.;
proc print noobs;
run;
![]() |
Output |
- PUT Function is used to convert the numeric variable to character format.
- INPUT Function is used to convert the character variable to sas date format
- FORMAT Function is used to display the SAS date values in a particular SAS date format. If we would not use format function, SAS would display the date in SAS datevalues format. For example, 20588 is a sas datevalue and it is equivalent to '14MAY2016'.