Help using Base SAS procedures

How to convert date to numeric

Accepted Solution Solved
Reply
Super Contributor
Posts: 297
Accepted Solution

How to convert date to numeric

Hello I have this variable Hosp_adm which I want to convert to nummeric. 

 

The data is below:

SAS Output

Obs Hosp_adm
1 25JUL2016
2 27JUL2016
3 27JUL2016
4 11JUL2016
5 28JUL2016
6 29JUL2016
7 29JUL2016
8 29JUL2016
9 31JUL2016
10 28JUL2016

 

 

data baseline;
set baseline;
new_Hosp_adm=input(Hosp_adm, date9.);
format new_Hosp_adm date9.;
run;

 

Please can anyone correct the code for me???


Accepted Solutions
Solution
‎09-01-2016 03:43 PM
Super User
Posts: 5,083

Re: How to convert date to numeric

Your code looks correct as is.  What happens when you run it?

 

Did you run a PROC CONTENTS to verify that this hasn't already been done?  Maybe HOSP_ADM is already numeric, with a DATE9 format used for printing.

View solution in original post


All Replies
Solution
‎09-01-2016 03:43 PM
Super User
Posts: 5,083

Re: How to convert date to numeric

Your code looks correct as is.  What happens when you run it?

 

Did you run a PROC CONTENTS to verify that this hasn't already been done?  Maybe HOSP_ADM is already numeric, with a DATE9 format used for printing.

SAS Employee
Posts: 5

Re: How to convert date to numeric

SAS stores calendar dates as numeric values. That is, a date is stored as a value that represents the number of days since the calendar date January 1, 1960. For example, the value for January 1, 1960 is 0. The value for January 1, 1961 is 366. SAS converts date values back and forth between calendar dates with SAS informats and formats. If you do a PROC CONTENTS on your data set, you will probably see that the variable is a numeric with an informat applied to it. You should be able to perform calculations on the column.  

Super Contributor
Posts: 297

Re: How to convert date to numeric

Thank you!!!

☑ This topic is SOLVED.

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

Discussion stats
  • 3 replies
  • 1548 views
  • 0 likes
  • 3 in conversation