|
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 14040 N. Northsight Blvd.
|
|
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: [hidden email] Subject: count occurrences of a character in a string To: [hidden email] 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 14040 N. Northsight Blvd.
Express yourself instantly with MSN Messenger! MSN Messenger |
| Free forum by Nabble | Edit this page |
