Precisely, we’ll flag non empty string values that are system missing after the conversion. compare the original to the converted variables.However, readers who struggle their way through will learn a very efficient solution that works for many other situations too. Solution 2: Copy String Variables Before Conversion Since we can’t undo the operation, let’s close our data without saving and reopen it. However, the other 3 variables contain system missings so we need to find out why. Since we’ve 480 cases in our data, we’re done for s1. Which is the format of our string values. This is why we set the correct f format: f6.3 means 6 characters including the decimal separator and 3 decimal places as in 12.345. Note: using alter type s1 to s4 (f1). will also work but the decimal places for s4 won’t be visible. *Close data without saving and reopen before proceeding.Īlter type s1 to s3 (f1) s4 (f6.3). If we don’t have any system missing values, we’re done. The syntax below converts all string variables in one go. * It allows us to convert many variables with a single line of syntax. The fastest way to convert string variables into numeric ones is with the ALTER TYPEcommand. Let’s speed things up by using some handy syntax. We’ll do just that in a minute.Īlthough safe, I still think this method is too much work, especially for multiple variables.
In our first example, the frequency table already suggested we must remove the “a” from all values before converting the variable. If N is lower than the number of non empty string values (frequencies before conversion), then something may be wrong. inspected N in a descriptive statistics after the conversion.inspected frequency tables: how many non empty values do we have before the conversion?.Right, so how can we perform the conversion safely? Well, we just And we usually won’t notice this problem because we don’t get any warning or error. Apparently, 15 values failed to convert -probably not what we want. We have 459 valid values (non empty cells).Īfter converting our variable to numeric, we ran some descriptives. We probably want these to be converted into numbers. Note that some values in our string variable have been flagged with “a”. That is, 15 values failed to convert and we’ve no clue why. *Now manually convert s3 to numeric under variable view. *Inspect frequency table for s3.įrequencies s3. *Set empty string as user missing value for s3. convert s3 to numeric in variable view.set empty cells as user missing values for s3.Well, let’s do it rather than read about it. it doesn’t generate any syntax: there’s no Paste button and nothing’s appended to my journal file.
WHAT ARE STRING VARIABLES SPSS CODE
The code I have written but doesn't work is the following: IF (ID1 = AAAA) AND (ID2 = 01) OpenText = "NIGHT". I am not sure what is the type of the variables: in the variable view, they are all nominal. My aim is to change some of the values of the OpenText depending on the value in both of the ID variables. The responses in the OpenText vary greatly. I will need to use both ID1 and ID2 to identify each row.
I have a dataset that looks like the one below.