您好,我是SPSS宏的初学者。我想知道人们是否可以告诉我是否可以使用宏在if语句中包含参数,例如
DEFINE !calc_spells (procedure = !TOKENS(1)).
*** Get the file.
get file ='C:\Users\mycomputer\Documents\file.sav'.
compute proc=0.
do repeat a=op1a to op4b.
if any(substr(a,1,4), !procedure) proc=1.
end repeat.
execute.
select if proc=1.
execute.
string procedure(a4).
compute procedure=!procedure.
*** aggregate file.
aggregate outfile=*
/break year procedure
/median_cost median_stay = median(cost_spell_total_net total_stay)
/number_of_spells = n.
save outfile=!path_output + !QUOTE(!CONCAT(!procedure, '_output.sav')).
!enddefine.
!calc_spells procedure = A021.
!calc_spells procedure = A024.
基本上我想知道是否可以针对不同的过程代码重复此宏,而不是每次运行时都手动更改代码?似乎我的代码没有工作,因为我根本没有任何案例?
答案 0 :(得分:1)
要让宏运行procedure
的几个值,您可以使用宏循环:
DEFINE !calc_spells (procedureList = !cmdend).
!do !procedure !in (!procedureList)
...
[your original macro content]
...
!doend
!enddefine.
!calc_spells procedureList = A021 A024 A025 A026.