| Date: | Mon, 4 May 2009 09:48:08 -0500 |
| Reply-To: | Mary <mlhoward@AVALON.NET> |
| Sender: | "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU> |
| From: | Mary <mlhoward@AVALON.NET> |
| Subject: | Re: what wrong with my code ? |
|
| Content-Type: | text/plain; format=flowed; charset="Windows-1252";
reply-type=original |
And the questioner needs to verify that it is the LAST four characters that
are not blank that he or she wishes to remove.
-Mary
----- Original Message -----
From: "Joe Matise" <snoopy369@GMAIL.COM>
To: <SAS-L@LISTSERV.UGA.EDU>
Sent: Monday, May 04, 2009 9:42 AM
Subject: Re: what wrong with my code ?
> Actually, LENGTH should trim the trailing blanks fine. (From the
> documentation:
> "Returns the length of a non-blank character string, excluding trailing
> blanks, and returns 1 for a blank character string")
>
> To avoid errors printing in the log, it's better to say:
> if length(val) GT 4 then y = ...
> and then have an alternate processing method if it's LE 4.
>
> However, given the data, it's possible that NAME is always GT 4, in which
> case this is not the error - hence the request for more information.
>
> -Joe
>
>
> On Mon, May 4, 2009 at 9:37 AM, karma <dorjetarap@googlemail.com> wrote:
>
>> try striping the trailing blanks before passing to substring with
>> either trim or strip.
>>
>> Joe raises a good point in that for strings less than 4 in length, you
>> will get undesirable results. You could use an if-then to handle these
>> cases, or if you have sas9 then the coalescec or the ifn function can
>> help abbreviate the code. Possibly something like the following:
>>
>> y=coalescec(substr(val, 1,length(trim(val))-4),val) ;
>>
>> Not tested: don't have SAS9.
>>
>> 2009/5/4 ash007 <RamsamyAshley@gmail.com>:
>> > Hi,
>> >
>> > how can I remove the last 4 characters.
>> >
>> > this code doesn't work.
>> >
>> > thanks.
>> >
>> >
>> > data datasetlist_new;
>> > set datasetlist;
>> > if upcase(x) = "TEMP" then y = substr(Name,1,length(Name)-4);
>> > run;
>> >
>>
|