Quantcast
Channel: ListenData
Viewing all articles
Browse latest Browse all 425

SAS : Converting Number Format to Date Format

$
0
0
This tutorial focuses on converting a number format variable to a date format variable.
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
Sample Data

The following program is used to create a sample data.
data temp;
input date;
cards;
20160514
19990505
20131104
20110724
;
run;
Solution
data temp2;
set temp;
newdate = input(put(date,8.),yymmdd8.);
format newdate date10.;
proc print noobs;
run;
Output
Explanation

  1. PUT Function is used to convert the numeric variable to character format.
  2. INPUT Function is used to convert the character variable to sas date format
  3. 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'.

Viewing all articles
Browse latest Browse all 425

Trending Articles