I have a dataset consisting of different groups, all of which have their own variables and I am trying to combine information from different variables into a single variable. For this I use the following code:

compute Q31_complete=$sysmis.

if (HR_manager=1) Q31_complete=Q31_HR.

if (Bedrijfsarts2=1) Q31_complete=Q31_BA.

if (Werkleider2=1) Q31_complete=Q31_WL.

if (OR_verteg2=1) Q31_complete=Q31_OR.

APPLY DICTIONARY from *

/SOURCE VARIABLES = Q31_HR

/TARGET VARIABLES = Q31_complete.

Now, I have to do this same thing for a lot of different variables, which basically means copy-pasting these commands and changing 'Q31' to a different question number everywhere. For this I would like to use a macro, since it is easier and makes my syntax more organized. I have limited experience with macros (only used !CMDEND before), and came up with this:

Define compleet (x=!CMDEND).

compute !x_complete=$sysmis.

if (HR_manager=1) !x_complete=!x_HR.

if (Bedrijfsarts2=1) !x_complete=!x_BA.

if (Werkleider2=1) !x_complete=!x_WL.

if (OR_verteg2=1) !x_complete=!x_OR.

APPLY DICTIONARY from *

/SOURCE VARIABLES = !x_HR

/TARGET VARIABLES = !x_complete.

!ENDdefine.

compleet x=Q44.

However, this is not working. Does anyone know how I should program a macro to have it repeat a sequence of commands letting just the Qxx vary?