Saturday, February 18, 2012

Counting character number in text in excel

Been working hard on refreshing my excel memory because I am trying I am trying to get some data processed so as to import it all to SPSS.

The first step I took was the calculate the number of times specific characters occurred in the original texts.  After googling around, I found some experts' smart solutions as follow... though... unfortunately, I forgot which source it was that I learned it from.

Essentially, this task can be easily accomplished by the combination of the LEN (i.e.,length) and SUBSTITUTE (i.e., word substitution) functions.

For instance, the formula used to count how many times the character "R" occurs in the text string in cell I2 is LEN(I2)-LEN(SUBSTITUTE(I2,"R","")).


LEN(I2) counts the total number of characters in the cell.

SUBSTITUTE(I2,"R","") replaces all "R" in the string with "" or, essentially deletes "R" from the String.

LEN(SUBSTITUTE(I2,"R","")) part of the formula calculates the length of the string after the character R is removed.

LEN(I2)-LEN(SUBSTITUTE(I2,"R",""))
= (the numbers of characters in the text string with R(s))-(the numbers of characters in the text string without R(s))
=the number of R in the string.

I have gotten rid of the spaces between the characters in advance.  In case you want to do character count without taking spaces into account and not wanting to get rid of the spaces, you can use the trim function.

Moving on to my next missing... trying to figure out the best way to import the data into SPSS with the problem in mind... on this spreadsheet, texts such as pre-wd14R OR PRE-WD14P are variable names while numerical values in K and P columns alike are the values the respective variables for a specific participant.  In total, there are something like 20 participants....

That's gotta be something smarter than doing the copying and pasting thing.... but... what I am stuck with for now.

Should've learned my SQL better in my much younger years.

(UPDATE: Resolution to my issue: Importing multiple Excel columns of var names and values into SPSS)

No comments:

Post a Comment