date to numeric

Reply
Super Contributor
Posts: 303

date to numeric

How to I convert date below to numeric;

data a;

input DD

cards;

18JAN2012

12MAR2013;

run;

Super User
Posts: 3,238

Re: date to numeric

You read it in directly as a numeric:

data a;

format dd date9.;

input @1 DD date9.

cards;

18JAN2012

12MAR2013;

run;

Super Contributor
Posts: 303

Re: date to numeric

I want to have both dates and numerical date side by side. In short I want to create a second variable.

Super User
Posts: 3,238

Re: date to numeric

In SAS a "date" is a numeric column with a date format applied to it. There is no such thing as a "date type" in SAS only character and numeric columns.

I have supplied the code that will give you a SAS numeric column with a date format applied. This is all you need for date processing and reporting.

The only other way of storing a date in SAS is as a character column and these are of very limited usefulness:

data a;

format dd date9.;

input @1 DD date9.;

dd_char = put(dd, date9.);

cards;

18JAN2012

12MAR2013;

run;


Super Contributor
Posts: 303

Re: date to numeric

both dd_char and DD are identical. I want one to be numeric and the other should be the same .

You code gives me

DD                                    dd_char

18JAN2012                       18JAN2012

12MAR2013                      12MARS2013.

I want DD_Char to be numbers .

Super User
Posts: 3,238

Re: date to numeric

They display the same but if you examine the contents of the dataset, one is numeric and the other is character. If you simply want "numbers" try this. Bear in mind that the number you see is the number of days since 1 Jan 1960, so I fail to see the usefulness of such a column: 

data a;

format dd date9.;

input @1 DD date9.;

dd_char = put(dd, 12.);

dd_num = dd;

cards;

18JAN2012

12MAR2013;

run;

Super User
Posts: 19,167

Re: date to numeric

When you say numbers what are you expecting. Post sample input and output.

Ask a Question
Discussion stats
  • 6 replies
  • 302 views
  • 0 likes
  • 3 in conversation