Date to Numeric Conversion

Accepted Solution Solved
Reply
Occasional Contributor TB2
Occasional Contributor
Posts: 8
Accepted Solution

Date to Numeric Conversion

[ Edited ]

I am trying to convert a date variable into an 8 digit numeric field (YYYYMMDD).

 

Currently it is in MMDDYY10. format and informat.

 

Example:

What is occuring:

Current_DATE = 08/01/2015 

 

What I want:

Current_Date = 20150801

 

Any suggestions?

 

 

 

 


Accepted Solutions
Solution
‎03-16-2016 04:56 PM
Super User
Posts: 5,388

Re: Date to Numeric Conversion

First question: why?

Storing as a date will give you all the flexibility of using formats and functions adopted for dates.

If you persist, nest input() and put() functions.

Data never sleeps

View solution in original post


All Replies
Solution
‎03-16-2016 04:56 PM
Super User
Posts: 5,388

Re: Date to Numeric Conversion

First question: why?

Storing as a date will give you all the flexibility of using formats and functions adopted for dates.

If you persist, nest input() and put() functions.

Data never sleeps
Occasional Contributor TB2
Occasional Contributor
Posts: 8

Re: Date to Numeric Conversion

Thanks. 

 

I am setting up datasets to run through a SAS program that someone else wrote. The instructions say to use numeric values for dates.

 

Here is the code I used for reference:

 

DATA ENROLLMENT_UPDATE;
  SET ENROLLMENT;
  DOBNEW=input(PUT(DOB, yymmddn8.),8.);
RUN;
Super User
Posts: 5,368

Re: Date to Numeric Conversion

DOB is (probably) already numeric.  So when you say that the program expects numeric values, you need to know which numeric values it expects.  It may be that you don't need to change a thing.

Super User
Posts: 19,167

Re: Date to Numeric Conversion

You can Keep it as a SAS date but display it that way  

 

format date yymmddn8.;

 

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 336 views
  • 3 likes
  • 4 in conversation