|Date: ||Fri, 11 Sep 2009 05:36:27 +0000|
|Reply-To: ||Ruben van den Berg <firstname.lastname@example.org>|
|Sender: ||"SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>|
|From: ||Ruben van den Berg <email@example.com>|
|Subject: ||Re: count occurrences of a character in a string|
Maybe something like this?
data list free/var(a20).
'al,mos,t' 'week,,,end' 'lots' 'of beer' 'co,m,i,ng m,,y way'
loop #i=1 to length(var).
do if sub(var,#i,1) eq ','.
Ruben van den Berg
Date: Thu, 10 Sep 2009 14:38:02 -0700
Subject: count occurrences of a character in a string
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.
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).
Market Research Manager
14040 N. Northsight Blvd.
Scottsdale, AZ. 85260 USA
Tel: 480-304-6832 Fax: 480-483-8352
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!