NebulousReveal
NebulousReveal

Reputation: 572

Date Error in SAS

How do you convert a mmddyy variable to a date9 variable? For example, suppose we have the following:

    x = 05/10/2011

I want x to be of the form 10May2011. So I did the following:

   xnew = put(x, date11.);

But for some reason there is an error (date11 is not a recognized format). Why? I am guessing you cannot convert from one date format to another date format? You have to first convert the format back to the sas internal value (number of days from January 1, 1960) and then convert it to date11?

Upvotes: 2

Views: 408

Answers (1)

Jay Corbett
Jay Corbett

Reputation: 28441

SAS date and time variables are stored in SAS as numeric data. So all variables that can be formatted as dates are stored the same way...as a number.

In your example, in order to make X a date

x='05OCT2011'd;

then you can format it in any date format you want.

xnew = put(x, date11.);

If x did equal '05/10/2011', you can convert the character var to a numeric like this

xnew = input(x, mmddyy10.);

Also, date11. is a valid date format.

Upvotes: 7

Related Questions