Date: Wed, 7 Oct 2009 08:54:54 -0500
Reply-To: Joe Matise <snoopy369@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Joe Matise <snoopy369@GMAIL.COM>
Subject: Re: Convert month variable from character to numeric using 9.1
In-Reply-To: <98e57913-4ed8-4d9c-88a4-c9decc2242ab@m18g2000vbs.googlegroups.com>
Content-Type: text/plain; charset=ISO-8859-1
The MONYY. informat should read it in, if you append a year to it (either 2
or 4 digit).
So:
newvar = input(cats(monvar,'09'),MONYY5.);
should do it. This assumes that it's stored as a character variable (format
$3. or similar). Of course it gives it a 2009 year, you may choose a
different one as your needs require [but you DO need to choose one].
Example:
data test;
input monvar $;
datalines;
JAN
FEB
MAR
DEC
;;;;
run;
data want;
set test;
format numvar MONYY5.;
numvar = input(cats(monvar,'09'),MONYY5.);
run;
proc print; run;
-Joe
On Tue, Oct 6, 2009 at 7:09 PM, JC <jencline10@gmail.com> wrote:
> i have a dataset with month stored as a separate variable as mmm.
> (JAN).
> I need to convert this to a numeric field so that i can use the mdy
> function.
>
> Can someone please help me convert the month field to numeric.
> I have tried the input function and it leaves my new variable blank.
>
> Thank you!
>
|