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 2011, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Sun, 13 Mar 2011 22:20:58 -0500
Reply-To:     Joe Matise <snoopy369@GMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Joe Matise <snoopy369@GMAIL.COM>
Subject:      Re: How can I replace the characters by a list in a fast way
Comments: To: Clark An <kuhasu@126.com>
In-Reply-To:  <773380d.9901.12eb25c8b64.Coremail.kuhasu@126.com>
Content-Type: text/plain; charset=UTF-8

Probably best to use one of the sort functions and then just iterate through it deleting duplicates, I suppose.

-Joe

2011/3/13 Clark An <kuhasu@126.com>

> > Thank you very much for your help.I will give it a try. > The case is: > an array with duplicate elements,some elements are not needed in a > condiciton such as <50; > but for the others, some of them are also not needed. > > And is there a way we can set up an array with not sure elements(I know we > can do it in fcmp ,array[1] _temp_),and make sure there are no duplicate > elements in the array? > > array orig[10] (1,1,2,2,2,3,5,1,1,2) > array test[1] _temp_ > do i=1 to 10; > j=1; > test(j)=orig(i);/*How can I make sure test[*]can keep the non-duplicate > elements*/ > j+1; > end; > end; > > > > At 2011-03-14 05:25:47,"Joe Matise" <snoopy369@gmail.com> wrote: > I imagine a simple do loop would work of course ... > > do __i = 1 to dim(ff); > c = tranwrd(c,cats("ff(",__i,")"),ff[__i]); > end; > > I don't think there is a CALL TRANWRD but if so that would be faster still. > Also you might test whether adding a IF FIND(...) would make it faster or > not- some cost to doing the find/index but might save time over TRANWRD, if > you only have a few instances in the string. > > If you want to improve over the do loop, particularly with a string like > that (short), you could do it backwards. Find the ( ) numbers, then replace > them. Something about like this probably would work. > > parencount = countc(c,')'); > do __i = 1 to parencount; > __arr = input(scan(c,2*__i,'()'),4.); > c = tranwrd(c,cats('ff(',__arr,')'),ff[__arr]); > end; > > To improve even over that you could probably rebuild the string as you went > instead of using the relatively expensive TRANWRD, but if you're only doing > four or five of them per string you're probably okay. However, if one ff(x) > value can occur more than once in the string, you risk an error as the > scan's iterator will stop tracking with the string - for production code you > should put in checks for that. > > This might be faster, though I don't like having to separately strip off > the 'ff'; I can't think of a good way to deal with it otherwise, though. > > parencount = countc(c,')'); > do __i = 1 to parencount; > __arr = input(scan(c,2*__i,'()'),4.); > before_arr = scan(c,(2*__i)-1,'()'); > before_arr = substr(before_arr,1,length(before_arr)-2); > new_c = cat(new_c,before_arr, ff[__arr]); > end; > > -Joe > > > On Sun, Mar 13, 2011 at 10:49 AM, Clark An <kuhasu@126.com> wrote: > array ff[250] (1,2,3....,250); > c='Mail a ff(4) of the ff(1) to ff(3) and ff(14) with ff(8)'; > > How can I use ff(x) to replace the 'ff(x)' in c string in a fast way pls? > And if I can get a list 4 1 3 14 8,then in which way I need to store the > list and then how to replace them(I mean if in a loop,but if there is a > faster way without loop,better!) > > TIA!! > > > > > >


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