Date: Mon, 2 Nov 2009 14:32:00 -0500
Reply-To: Gerhard Hellriegel <gerhard.hellriegel@T-ONLINE.DE>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Gerhard Hellriegel <gerhard.hellriegel@T-ONLINE.DE>
Subject: Re: sas date conversion
I assume that the date is like
yyyy-mm-dd
so the informats should be:
Chardate numericdate informat
2009-07-07 07JUL2009 yymmdd10.
2009-08-03 03AUG2009 yymmdd10.
2008-01 2008JAN
2007 2007 5.
2009-07-11 11JUL2009 yymmdd10.
for the 2008-01 I'd use the following:
mdy(input(scan(chardate,2,"-"),5.),1,input(scan(chardate,1,"-"),5.)
because that is no date.
Note that the numericdate like you present them are not native. That are
formatted values, otherwise
"2009-07-07" would be displayed like 18085.
Displaying a date-value like 2008JAN? Use yymon7.
A format to show only the year of a date-value - I don't know one. If you
want that, you can write a picture format, or use the YEAR function to
extract the year first.
Gerhard
On Mon, 2 Nov 2009 11:01:15 -0800, Barry Schwarz <schwarzb@DQEL.COM> wrote:
>If the character date is already in a SAS variable, use the INPUT
>function with an appropriate informat to convert the value to a SAS
>numeric date value. If it is in a text file, use the INPUT statement
>with the appropriate informat.
>
>Once you have a SAS date value, use the appropriate format to display
>the data.
>
>On Fri, 30 Oct 2009 06:24:00 -0700 (PDT), shruthi
><pramila.sami@gmail.com> wrote:
>
>>Hello all,
>>
>>I have a character date and I have to convert it into numeric date
>>
>>Chardate numericdate
>>2009-07-07 07JUL2009
>>2009-08-03 03AUG2009
>>2008-01 2008JAN
>>2007 2007
>>2009-07-11 11JUL2009
>>
>>How can I write a code to do this conversion. thanks
>
>--
>Remove del for email