LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (March 2000, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Sat, 4 Mar 2000 11:51:59 +0000
Reply-To:     Peter Crawford <Peter@CRAWFORDSOFTWARE.DEMON.CO.UK>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Peter Crawford <Peter@CRAWFORDSOFTWARE.DEMON.CO.UK>
Organization: Crawford Software Consultancy Limited
Subject:      Re: Strange variable behaviour

I expect index() uses the whole length of the variable in its second parameter, so if that second parameter may contain trailing blanks that you want ignored, then you need the trim() within the index() i.e. not > hit=index(names,stuff); But > hit= index( names, trim( stuff ) );

This must be worth trying...... so, here is the resulting data set +FSVIEW: WORK.DATA5 (B)----------------------------------+ | OBS A B C NAMES I HIT STUFF | | | | 1 it of ash angelas ashes 3 9 ash | | 2 it of ash star wars 4 0 ash | | 3 it of ash let it ride 1 5 it | | | +---------------------------------------------------------+

Philp, Stephen R. <Stephen.Philp@CSHS.ORG> writes >Okay, I'll admit my array processing is in its infancy, but for the life of >me, I can not work this one out in my head. I would love to know the why >behind the works. >*First set up a little data; >data data1; >input a $ b $ c $; >cards; >it of ash >; > >data data2; > infile cards truncover; > input names $40.; >cards; >angelas ashes >star wars >let it ride >; >*now do some processing; >*this construct works and hit gets populated correctly; >data data3; > if _n_=1 then set data1; > set data2; > array search(3) $ a b c; > do i=1 to 3 until(hit); > hit=index(names,trim(left(search{i}))); > end; >proc print data=data3; >run; >*this construct does not work and hit never gets populated; >data data4; > if _n_=1 then set data1; > set data2; > array search(3) $ a b c; > do i=1 to 3 until(hit); > stuff=trim(left(search{i})); > hit=index(names,stuff); > end; >proc print data=data3; >run; > >I believe that stuff is not inheriting the correct attributes, and some >padding with spaces is happening? But if I left and trim stuff after just >assigning it: >stuff=search{i}; >stuff=trim(left(stuff)); >It still doesn't work. I suspect a length statement would have solved this >but would not be easily facilitated in this piece of code (production code >is dynamic). >Anyone care to pass on some Guru knowledge on this? >Thanks again, >Stephen

-- Peter Crawford

Back to: Top of message | Previous page | Main SAS-L page