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 (November 2009, week 5)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Mon, 30 Nov 2009 16:39:03 +0100
Reply-To:     karma <dorjetarap@GOOGLEMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         karma <dorjetarap@GOOGLEMAIL.COM>
Subject:      Re: 4.29: How can I count the number of occurrences of a
Comments: To: kellogg <kel@log.co.uk>
In-Reply-To:  <DbSdnXbU-6CVqpDWnZ2dnUVZ_u6dnZ2d@earthlink.com>
Content-Type: text/plain; charset=ISO-8859-1

Hi Kellog,

Without seeing your code / pattern, I can only guess that it's because you didn't use positive/negative look ahead assertations. Assuming that you are looking for negative values in your string that aren't followed by characters, you can use the following pattern:

data _null_ ; str='-3 -5start -9 55 48 -2 23 -roger -76 4 14 -44 -nus- -189 - -44'; pattern = prxparse('/-\d+(?![a-z])/') ; start=1 ; stop=length(str) ; call prxnext(pattern, start, stop, str, position, length); do while (position) ; found = substr(str, position, length); put found= position= length=; call prxnext(pattern, start, stop, str, position, length); end; run ;

log; found=-3 position=1 length=2 found=-9 position=12 length=2 found=-2 position=21 length=2 found=-76 position=34 length=3 found=-44 position=43 length=3 found=-189 position=53 length=4 found=-44 position=60 length=3

2009/11/25 kellogg <kel@log.co.uk>: > the lengths do not appear to be correct > > consider this string > > str='-3 -5start -9 55 48 -2 23 -roger -76 4 14 -44 -nus- -189 - -44'; > > position=1 length=2 found=-3 > > position=11 length=3 found=-9 > > position=20 length=3 found=-2 > > position=33 length=4 found=-76 > > position=42 length=4 found=-44 > > position=52 length=5 found=-189 > > position=59 length=4 found=-44 >


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