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 (September 2009)Back to main SPSSX-L pageJoin or leave SPSSX-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Fri, 11 Sep 2009 05:36:27 +0000
Reply-To:   Ruben van den Berg <ruben_van_den_berg@hotmail.com>
Sender:   "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From:   Ruben van den Berg <ruben_van_den_berg@hotmail.com>
Subject:   Re: count occurrences of a character in a string
In-Reply-To:   <40A4A53F5727324F8ADCDF4A219CF681072E413C@mail5.worldatwork.org>
Content-Type:   multipart/alternative;

Dear Brian,

Maybe something like this?

data list free/var(a20).

begin data

'al,mos,t' 'week,,,end' 'lots' 'of beer' 'co,m,i,ng m,,y way'

end data.

comp commas=0.

loop #i=1 to length(var).

do if sub(var,#i,1) eq ','.

comp commas=commas+1.

end if.

end loop.

exe.

HTH,

Ruben van den Berg

Date: Thu, 10 Sep 2009 14:38:02 -0700 From: Brian.Moore@WORLDATWORK.ORG Subject: count occurrences of a character in a string To: SPSSX-L@LISTSERV.UGA.EDU

Hi all- How might one count the number of times a particular character appears in a string variable? The string variable is called Qg and commas are the character I want to count. I’m using version 15. Thanks in advance for any suggestions. Regards, Brian PS – context of the problem below if you are interested. & the problem at hand is using an open text field to collect numeric sales data and addressing multiple variations of uses of terms (mil, MM, millions, bil, Billions, etc.) and use of decimals and commas in that context. And of course to add to the fun data collected in ~20 countries [so the meaning of . and , appearing in a sales figure is opposite in some cases). I’ve addressed most of the issues (and have a few useful reasonableness checks in other variables), but this last piece has me stuck). Brian Moore Market Research Manager WorldatWork 14040 N. Northsight Blvd. Scottsdale, AZ. 85260 USA Tel: 480-304-6832 Fax: 480-483-8352 E-mail: brian.moore@worldatwork.org www.worldatwork.org

UPCOMING CONFERENCES: Total Rewards 2009 Asia Pacific Oct. 7-9 | Hong Kong

Total Rewards 2010 May 16-19 | Dallas / Ft.Worth, TX

_________________________________________________________________ Express yourself instantly with MSN Messenger! Download today it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/


[text/html]


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