I have a simple 2-variable example here. You can expand it to 40 (or however many) variables in your own case.
*My own sample data. You have your own "a" variables.
data list free /a1 a2 (2a32).
begin data.
E10VALUES E11ANDMORECHARACTERS
E12STUFF E10VALUE
end data.
*You would change "x1 to x2" in the NUMERIC and VECTOR commands below to "x1 to x40" for your own data. The VECTOR command for "#a" would be your own existing string variables.
numeric x1 to x2 (F2).
vector x=x1 to x2.
vector #a=a1 to a2.
*The LOOP command would change to 1 to 40.
loop #i=1 to 2.
compute x(#i)=0.
if substr(#a(#i),1,3)="E10" x(#i)=1.
if substr(#a(#i),1,3)="E11" x(#i)=2.
end loop.
execute.
Then you could use the COUNT command to create new variables that count any target value(s) of your "x" variables. See help for COUNT for details.
------------------------------
Rick Marcantonio
Quality Assurance
IBM
------------------------------
Original Message:
Sent: Sun December 13, 2020 09:30 PM
From: Zubair Khan
Subject: Recoding string variable in to a new numeric variable
I have a large dataset where I need to:
- Recode 40 string variables to individual new numeric variables concatenating at least 20 different codes with varying character lengths by their first 3 characters such as 'E10', E11' for 2 of these codes and convert them as 1, 2 and rest as 0 - plus account for missing values.
- Identify all 1's and 2's for converted variables and transform them to a single new numeric variable for individual subjects.
Any help will be much appreciated.
------------------------------
ZKhan
------------------------------
#SPSSStatistics