0
votes

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:

  1. 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.
  2. 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.

2
Macro's don't work like that - you don't have access to any case attributes. So when running 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 use INSERT before Python was an option.Andy W
Thanks, I feared as much. By written out syntax do you mean every computation command for its own and brought together in a single syntax file? Concerning Python: Do you know if with the python AddIn I can reference to Values from the variables directly? Say, i can loop over the content of e.g. a label object or the like?DatenBergwerker
Here is an example of the writing out a file, spsstools.net/de/syntax/462. I can't quite understand what your question about Python is asking - but the answer is probably yes. Python basically exposes access to everything.Andy W
A macro isn't required here. Python will definitely solve this easily, but if you really can't, I can write you a syntax workaround - i'll just need a better explanation of what you actually want to get to.eli-k
Basically I just want to loop over the features of v601, check which cases have the same value as the current feature and create a variable with the name "wasnot<current feature label>". Afterwards I want to check which cases possess the current feature and assign 0 / 1 according to the wasnot variable. Then it will be crosstabbed with always the same variable. e.g. Iteration 1: compute <wasnotFeatureValueLabel for 1> -> Is your V601 Value = 1? If yes <wasnot...> = 0, if no <wasnot...> = 1. -> crosstab wasnot with v15 (but always the same) in Iter2: ValLabel 2 and check if V601 = 2 and so onDatenBergwerker

2 Answers

1
votes

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.

0
votes

Thanks for all the Help. In the end I did it with generating new syntax using Outfile.