Date: Wed, 8 Dec 2004 18:20:32 -0600
Reply-To: "Dunn, Toby" <Toby.Dunn@TEA.STATE.TX.US>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Dunn, Toby" <Toby.Dunn@TEA.STATE.TX.US>
Subject: Re: Problems with INDEX in variable
Content-Type: text/plain; charset="iso-8859-1"
Well Ya and Paul I am wrong, it padding it with trailing blanks. Guess I need to go forth and take a long break tonight and dump my memory stacks for a while.
Thanks,
Toby
________________________________
From: SAS(r) Discussion on behalf of Ya Huang
Sent: Wed 12/8/2004 5:48 PM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Re: Problems with INDEX in variable
David,
I myself was kind supprised to see that result. After look at
it carefully, I now understand why it behaved that way:
1 data _null_;
2 uid='07496DSGPRDALBU2249';
3 uidmask = '**********DSGPRD';
4 found = index(uid,compress(uidmask,'*'));
5 put _all_;
6 run;
uid=07496DSGPRDALBU2249 uidmask=**********DSGPRD found=6 _ERROR_=0 _N_=1
Note the above code do not use a intermediate variable uidmask, instead
it nested compress() inside the index(), and it works fine. The reason your
original code did not work, I believe is because the assigment
uidmask=compress(uidmask,'*');
since uidmask has already been define with certain length, a new value
assigned to it, when shorter than its length, will automatically get padded
with blanks.
Ya
On Wed, 8 Dec 2004 18:10:47 -0500, David W Neylon
<david.w.neylon@WELLSFARGO.COM> wrote:
>Thanks to Ya Huang and Ben Krone,
>
> Indeed trim solved the problem. And evidently compress created it by
>taking out the *'s and leaving spaces at the end.
>
>Thanks to everyone for their time.
>
>David Neylon
>
>On Wed, 8 Dec 2004 18:00:45 -0500, Ya Huang <ya.huang@AMYLIN.COM> wrote:
>
>>
>>David,
>>
>>You need a trim():
>>
>>23 data _null_;
>>24 uid='07496DSGPRDALBU2249';
>>25 uidmask = '**********DSGPRD';
>>26 uidmask = compress(uidmask,'*');
>>27 dum='#'||uidmask||'#';
>>28 found = index(uid,trim(uidmask));
>>29 put _all_;
>>30 run;
>>
>>uid=07496DSGPRDALBU2249 uidmask=DSGPRD dum=#DSGPRD # found=6
>>_ERROR_=0 _N_=1
>>
>>See how the uidmask is still not trimed by compress ?
>>
>>It is weird though.
>>
>>Ya
|