LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (February 2012, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
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
Comments: To: Sas Beginner <cep@stuntz.org>
In-Reply-To:  <201202091608.q19F1due031657@waikiki.cc.uga.edu>
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).

IE:

enddate=input(enddate_char,MMDDYY8.);

The only possible issue I could forsee is if it is something like 051980 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.

-Joe

On Thu, Feb 9, 2012 at 10:08 AM, Sas Beginner <cep@stuntz.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 > use? > > 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. >


Back to: Top of message | Previous page | Main SAS-L page