Reputation: 29
Hi I'm a beginner with SPSS macros. i wonder if people can tell me if it is possible to have parameter in the if statement using macro, for example
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.
Basically I would like to know if this macro can be repeated for different procedure codes instead of changing the code manually each time I run? it seems my code is not working as I get no cases at all?
Upvotes: 2
Views: 223
Reputation: 11350
To get the macro to run over a few values of procedure
, you can use a macro loop:
DEFINE !calc_spells (procedureList = !cmdend).
!do !procedure !in (!procedureList)
...
[your original macro content]
...
!doend
!enddefine.
!calc_spells procedureList = A021 A024 A025 A026.
Upvotes: 1