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 (October 2004, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 15 Oct 2004 16:55:15 -0400
Reply-To:     John Kramer <kramer@JIMMY.HARVARD.EDU>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         John Kramer <kramer@JIMMY.HARVARD.EDU>
Subject:      Re: Informats

On Fri, 15 Oct 2004 11:26:40 -0700, Rick James <dadagbemi@YAHOO.COM> wrote:

>A short program: > >data temp; > format Name $ 10. Date date9.; > input Name $ Date date9.; > datalines; >Ben 23-May-03 >Monica 8-Feb-02 >George 1/1/2004 >John 4-Dec-01 >; >proc print;run; > >Ok, so we all know that the date for George will be invalid because >its not in the correct informat. What I want to do is find a way to >get around this. I have over 10000, with about half of the date9. >informat and half mmddyy10. Any ideas? What I was thinking was >probably during the input statements, if an error is encountered, that >line is reread and a different informat is used then the value >assigned to Date. Is this even possible, will it ever be?

You can try something like this:

data temp; format Name $ 10. Date_txt $ 9.; input Name $ Date_txt $; datalines; Ben 23-May-03 Monica 8-Feb-02 George 1/1/2004 John 4-Dec-01 ; run;

data temp(drop=Date_txt); set temp; Date = input (Date_txt, date9.); if _error_ = 1 then do; _error_ = 0; Date = input(Date_txt, mmddyy10.); end; format Date date9.; run;

proc print;run;

I only tested this very briefly, but this should get you what you want.

John


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