SAS : Converting Number Format to Date Format

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'.

Best Online Course : Practical SAS Programming with 50+ Case Studies

- Explain Programming Concepts in Simple English
- Live Projects & Case Studies
- Job Placement Assistance
- Money Back Guarantee


SAS Tutorials : 100 Free SAS Tutorials

About Author:

Deepanshu founded ListenData with a simple objective - Make analytics easy to understand and follow. He has close to 7 years of experience in data science and predictive modeling. During his tenure, he has worked with global clients in various domains like retail and commercial banking, Telecom, HR and Automotive.


While I love having friends who agree, I only learn from those who don't.

Let's Get Connected: Email | LinkedIn

Get Free Email Updates :
*Please confirm your email address by clicking on the link sent to your Email*

Related Posts:

0 Response to "SAS : Converting Number Format to Date Format"

Post a Comment

Next → ← Prev