Date: Wed, 6 Aug 2003 09:38:01 -0400
Reply-To: Venky Chakravarthy <venky.chakravarthy@PFIZER.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Venky Chakravarthy <venky.chakravarthy@PFIZER.COM>
Subject: Re: Best way to trim a variable?
Dave,
Your method will work as long as the length of the true string is
guaranteed to be 9. A more dynamic approach may be prudent.
Assuming that you want the first position in the string to be
occupied by a non-number then you may want to VERIFY that first.
%let verify = verify(string,'0123456789') ;
This will return the first position occupied by a character not found in
the quoted string. Here is a method that obviates the need for a new
variable. :
data _null_ ;
length string $12 ;
input string $ ;
if &verify.>1 then
substr(string,1,&verify.-1) = "";
put string = ;
cards ;
100AA1234567
101AB1234567
BA1234567
BB1234567
run ;
Kind Regards,
Venky
On Tue, 5 Aug 2003 23:38:11 +0000, Dave Meyer <dmeyer@HOAGHOSPITAL.ORG>
wrote:
>TNX Arto!
>
>Before recieving your (and others) responses - all of which suggest
>using LENGTH with an IF statement, I tried the syntax below. It works,
>however, since so many suggestions use LENGTH and an IF statement, I am
>wondering if I am missing somthing...or doing somthing (in the code
>below) that I shouldn't do...?
>
>Any thoughts?
>
>TIA again (everyone),
>
>Dave
>
>__________________________
>
>
>DATA WORK.play1;
>FORMAT membnum $12. ;
>FORMAT B $9. ;
>INPUT MembNum $ ;
> B = reverse(substr(reverse(trim(membnum)),1,9)) ;
>DATALINES;
>101AA1234567
>BB1234567
>;
>proc print ;
>
>run ;
>
>
>____________________________
>
>"Arto Raiskio" <arto.raiskio@suomenposti.com> wrote in message
>news:bgpchu$rft7a$1@ID-102906.news.uni-berlin.de
>
>> "Dave Meyer" wrote
>> > Existing data:
>> >
>> > 100AA1234567
>> > 101AB1234567
>> > BA1234567
>> > BB1234567
>> >
>>
>> data _null_; length stuff $ 12;
>> input stuff $;
>> if length(stuff)=12 then newstuff=substr(stuff,4,9);else newstuff=stuff;
>> put stuff= newstuff=;
>> datalines;
>> 100AA1234567
>> 101AB1234567
>> BA1234567
>> BB1234567
>> ;
>> run;
>
>
>
>
>--
>Posted via Mailgate.ORG Server - http://www.Mailgate.ORG
|