Date: Thu, 9 Feb 2012 10:13:04 -0600
Reply-To: Joe Matise <snoopy369@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Joe Matise <snoopy369@GMAIL.COM>
Subject: Re: cleaning data" dates
Content-Type: text/plain; charset=ISO-8859-1
If you just try to INPUT it with the correct informat (looks like
MMDDYY8.), it will either work (give you a valid result) or not work (give
you missing) if it is not a valid date format (ie, not as you say below).
The only possible issue I could forsee is if it is something like
which is not 8 long of course, and would translate into 05/19/80 (1980) but
could as easily be 05/xx/1980. If that result is okay then let it go;
otherwise verify the length (using LENGTH) of the variable first.
On Thu, Feb 9, 2012 at 10:08 AM, Sas Beginner <firstname.lastname@example.org> wrote:
> i need to clean a dataset. the date variables are character. what is the
> easiest way to verify it is a valid date and convert it to variable with a
> date format.
> is this the easiest or is there a sas macro or common code that i could
> yy = input (substr(enddate_char,1,4), 8.);
> mm = input (substr(enddate_char,5,2), 8.);
> dd = input (substr(enddate_char,7,2), 8.);
> verify yy, mm (1-12 inclusive), dd (1-31)
> if yy, mm and dd passed the verification, then endate = mdy (mm,dd,yy);
> thank you.