string - SPSS REPEAT: How do i use the stand-in-variable as part of variable name? -


i'm using spss 20. in dataset list of string variables want recoded numeric. wanted them recoded themselves. realize not possible spss runs through dataset casewise , 1 variable can have 1 type @ time. want them recoded new variables suffix _rec.

do repeat var = var_1 var_2 ... var_n.   recode var (convert) var_rec. end repeat.  

but creates 1 new variable var_rec not several new ones.

i tried programme workaround:

compute job_2 string job(a20)     repeat var = var_1 var_2 ... var_n. compute var = job.  recode job (convert) job_2. delete variables var. compute var = job_2.   end repeat.  

but doesn't work because delete variables can not used within do repeat loop.

so i'm @ original question.

you (string variables) can't recoded can using alter type

alter type var_1 var_2 var_3 (f8.2).  

where f8.2 numeric variable of width 8 , 2 decimal points.

you can use do repeat multiple stand-in list of variables, following:

do repeat old = var_1 var_2 var_3     /new = var1_rec var2_rec var3_rec.   recode old (convert) new. end repeat print.  

which expanded out equivalent to:

recode var_1 (convert) var1_rec. recode var_2 (convert) var2_rec. recode var_3 (convert) var3_rec. 

but if going can within recode command directly, this:

recode var_1 var_2 var_3 (convert) var1_rec var2_rec var3_rec. 

both methods assume original variables string variables (of , differing widths).

take note of convert function does, namely, taking string variable (containing numeric values stored string) , converting numeric format variable. input variable string , output numeric.


Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -