loops - SPSS: Use index variable inside quotation marks -
i have several datasets on want run identical commands. basic idea create vector names of datasets , loop on it, using specified name in command:
vector=(9) d = name1 name9. loop #i = 1 9. file = directory\d(#i).sav value labels v1 v8 'some text d(#i)' loop end.
now spss doesn't recognize want use specific value of vector d. in stata i'd use
local d(v1 v8) foreach d{ ....`d' ..... }
you can't use vector
in way i.e. using get
command within vector/loop
loop.
however can use define/!enddefine. spss's native macro facility language, if not aware of this, you'll need lot of reading on , understand it's syntax usage.
here's example:
define !runjob () !do !i !in 1 !to 9 file = !concat("directory\d(",#i,").sav"). value labels v1 v8 !quote(!oncat("some text d(",#i,")", !doend !enddefine. set mprint on. !runjob. set mprint off.
all code between define
, !enddefine
body of macro , syntax near end !runjob.
runs , executes procedures defined in macro.
this use of macro no parameters/arguments assigned there scope more complexity.
if new define/!endefine
suggest not invest time in learning instead learn python program ability can used achieve same (and more) relative ease compared define/!enddefine.
a python solution example (you need python programmability integration spss):
begin program. in xrange(1,9+1): spss.submit(""" file = directory\d(%(i)s).sav value labels v1 v8 'some text d(%(i)s)'.""" % locals()) end program.
as notice there more simplicity python solution.
Comments
Post a Comment