Reputation: 193
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:
Please note, working with the Python AddIn is sadly not an Option. I'm grateful for any received advice.
Upvotes: 0
Views: 584
Reputation: 193
Thanks for all the Help. In the end I did it with generating new syntax using Outfile.
Upvotes: 0
Reputation: 5417
There is an extension command, SPSSINC CREATE DUMMIES, that will create all these dummy variables automatically. It's on the Transform menu. And it is implemented in Python.
Using Python you can easily read case data and do lots more.
Upvotes: 1