Date: Tue, 4 Jan 2005 08:59:27 -0800
Reply-To: sportsfun77@HOTMAIL.COM
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: sportsfun77@HOTMAIL.COM
Organization: http://groups.google.com
Subject: Re: how to change date format mm-dd-yy to mm/dd/yy?
Content-Type: text/plain; charset="iso-8859-1"
Thank you for your help, Chang!
One more question. I noticed there are several cases in the source data
that just report the mmyy(for example, 12-96 or 05-97). There are also
a few cases report 06-31-98 or 09-31-97. Clearly it is a type error (it
should be 06-30-98 or 09-30-97). For these special cases, sas gives an
error message "Invalid argument to function INPUT" when I change the
date format as you suggested. Is there a way to treat these special
cases?
Thanks a lot!
Chang Y. Chung wrote:
> On Tue, 4 Jan 2005 06:38:44 -0800, sportsfun77@HOTMAIL.COM wrote:
>
> >Thank you for your help. I think I need to state my question
clearer.
> >My source data is character variable, when I follow your suggestion,
I
> >got 'Invalid numeric data, PRXDATE='12-31-97''.
> >
> >I guess this may be related to the INFORMAT and FORMAT of COMMAw.d,
and
> >the variable should be given an INFORMAT and FORMAT of MMDDYYw..
But I
> >am not sure how to do this and at the same time change the format to
> >mm/dd/yy. Would you please help me with this?
>
> Hi, sportsfun77,
>
> Of course I am not Alan, but if I may be allowed to butt-in.... :-)
>
> Here is one way. I kind of like the convention of coding attrib
statement
> first, when you create a new variable in a data step -- which seems
to
> encourage programmers to plan ahead and to put all the code used to
create
> the variable in one place.
>
> Cheers,
> Chang
>
> /* test data */
> data one;
> oldDate = "08-03-98"; output;
> oldDate = "08-04-97"; output;
> run;
>
> /* convert to a numeric variable with a date format associated */
> data two;
> set one;
>
> attrib newDate format=mmddyys8. label="converted from var oldDate";
> newDate = input(oldDate, mmddyy8.);
>
> run;
>
> /* check */
> proc print data=two;
> run;
> /* on lst
> Obs oldDate newDate
>
> 1 08-03-98 08/03/98
> 2 08-04-97 08/04/97
> */
|