DatenBergwerker
DatenBergwerker

Reputation: 193

SPSS Macro - Generate dynamic Varnames

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:

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.

Upvotes: 0

Views: 584

Answers (2)

DatenBergwerker
DatenBergwerker

Reputation: 193

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

Upvotes: 0

JKP
JKP

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

Related Questions