Date: Mon, 23 Feb 2009 23:01:04 +0530
Reply-To: Anindya Mozumdar <anindya.lugbang@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Anindya Mozumdar <anindya.lugbang@GMAIL.COM>
Subject: Re: pit numeric and charactor variables from string.
In-Reply-To: <5bf1e09f-3f1b-4d4e-ba0d-960bc9d28484@m42g2000yqb.googlegroups.com>
Content-Type: text/plain; charset=ISO-8859-1
On Mon, Feb 23, 2009 at 3:34 PM, babu <ajay.reddy2007@gmail.com> wrote:
> Hi All,
> I have a input data that has values numeric with charactor ,Now
> I want to separate these into two variables -numvar & charvar; where
> numvar will hold values that are all numeric and
> charvar will have values that are all alphabets.Could you please tell
> me how can I do that
> Example
> INput :-
>
Just for fun (Nat's solution is better) -
data test;
length x $50;
x = "LIC091insurance"; output;
x = "ICICIOPRULIFE012ULIP"; output;
x = "AVIVALIFE032Generalinsurance"; output;
run;
data test2;
set test;
length c1 $20 n1 $20 c2 $20;
c1 = substr(x, 1, anydigit(x)-1);
n1 = substr(x, anydigit(x), anyalpha(substr(x, anydigit(x)))-1);
c2 = substr(substr(x, anydigit(x)), anyalpha(substr(x, anydigit(x))));
run;
Regards,
Anindya
|