Date: Thu, 9 Dec 2004 11:16:32 -0500
Reply-To: Jim Groeneveld <jim1stat@YAHOO.CO.UK>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Jim Groeneveld <jim1stat@YAHOO.CO.UK>
Subject: Re: Q on extracting data from a variable
Content-Type: text/plain; charset=ISO-8859-1
Hi Rahul and Toby,
I included an explicit space in the delimiting specification ' -', because
I think it to be better, though leading and trailing spaces often are being
ignored, with PUT, but especially if using INPUT to make it numeric. And I
made them numeric as well.
Furthermore, if leaving them character, the first assignment might
determine the length, possibly leaving insufficient length for later ones.
So you should define lengths in advance. On the other hand I remember a
posting of myself in which I showed a default length of 200 from the SCAN
function (URL may be divided over two lines!):
http://listserv.uga.edu/cgi-bin/wa?A2=ind0207A&L=sas-
l&P=R26271&D=1&H=0&O=D&T=1
So even in that case it would be wise to define a (shorter) length in
advance.
The following program shows the difference between '-' and ' -' as the
delimiting character(s) in the SCAN function:
DATA _NULL_;
a = '1 - 2 - 3';
a1 = SCAN (a, 1, '-');
a2 = SCAN (a, 2, '-');
a3 = SCAN (a, 3, '-');
la1 = LENGTH(a1);
la2 = LENGTH(a2);
la3 = LENGTH(a3);
b1 = SCAN (a, 1, ' -');
b2 = SCAN (a, 2, ' -');
b3 = SCAN (a, 3, ' -');
lb1 = LENGTH(b1);
lb2 = LENGTH(b2);
lb3 = LENGTH(b3);
PUT (_ALL_)(=)'***';
RUN;
It proves the recommendation to also define the space as a delimiter.
Regards - Jim.
--
Y. (Jim) Groeneveld, MSc., Biostatistician, Science Team
Vitatron B.V., Meander 1051, 6825 MJ Arnhem
P.O.Box 5227, 6802 EE Arnhem, the Netherlands
Tel: +31/0 26 376 7365, Fax: +31/0 26 376 7305
Jim.Groeneveld_AT_Vitatron.com (replace _AT_ by AT sign)
http://www.vitatron.com, http://home.hccnet.nl/jim.groeneveld
On Thu, 9 Dec 2004 07:06:39 -0800, RAHUL CHAHAL <rahulchahal@YAHOO.COM>
wrote:
>Hi,
>Would like to find out how to extract the following values of a variable:
>
>Acct
>1 - 1111 - 123456
>1 - 121212 - 9876543
>1 - 21212 - 909045600
>99 - 32435465 - 121
>
>Into 3 variables:
>
>Acct1 Acct2 Acct3
>1 1111 123456
>1 121212 9876543
>1 21212 909045600
>99 32435465 121
>
>Thanks for your help.
>
>Rahul
>
>
>
>
>
>
>---------------------------------
>Do you Yahoo!?
> Meet the all-new My Yahoo! – Try it today!
|