I am currently trying to create dynamic variable names based on the valuelabels of the passed Argument. Currently, I have something like this:
COMPUTE counter = 0.
APPLY DICTIONARY FROM *
/SOURCE VARIABLES = V601
/TARGET VARIABLES = counter.
DEFINE !macro1 (!POS !CMDEND).
STRING name (A20).
!DO !#i = 1 !TO 62
COMPUTE counter = #i
!IF (!POS !EQ !i)
!THEN
COMPUTE name = VALUELABEL(!POS)
COMPUTE !CONCAT('wasnot', name) = 1.
!ELSE
COMPUTE name = VALUELABEL(!counter).
COMPUTE !CONCAT('wasnot', name) = 0.
!IFEND
!DOEND
CROSSTABS v15 by !CONCAT('wasnot', name) /cells = column.
!ENDDEFINE.
The idea is, that for every unique value of V601 a flag variable will be created (e.g. "wasnotvaluelabel1"). This variable will either have value = 1 or 0 respectively. However, it seems that concat cannot be used the way I intended. I get these errors:
Error # 6843 in column 7. Text: !POS The end of a macro expression occurred when an operand was expected. Execution of this command stops.
Error # 6846 in column 7. Text: !POS A macro expression includes an undefined macro variable or a macro operator which is not valid within an expression.
Error # 6836 in column 12. Text: !EQ In a macro expression, an operator was not preceded by an operand.
Error # 6846 in column 2. Text: !THEN A macro expression includes an undefined macro variable or a macro operator which is not valid within an expression.
Error # 6846 in column 28. Text: !POS A macro expression includes an undefined macro variable or a macro operator which is not valid within an expression.
Questions I have right now:
- Is it even possible to generate dynamic names? I have tried different attempts over the last hours but the SPSS macro "language" seems very restricted.
- Is there perhaps some other way to achieve this Task? It seems rather unconvenient.
Please note, working with the Python AddIn is sadly not an Option. I'm grateful for any received advice.
COMPUTE name = VALUELABEL(!POS)
it creates a variable called name in the dataset, but you do not have access to "name" in any macro statements. Python is the easiest solution, but people have hacky solutions to write out syntax and useINSERT
before Python was an option. – Andy W