Question

I have a spss syntax file that I need to run on multiple files each in a different directory with the same name as the file, and I am trying to too do this automatically. So far I have tried doing it with syntax code and am trying to avoid doing python is spss, but all I have been able to get is the code bellow which does not work.

VECTOR  v = key.

LOOP #i = 1 to 41.
GET 
  FILE=CONCAT('C:\Users\myDir\otherDir\anotherDir\output\',v(#i),'\',v(#i),'.sav').
  DATASET NAME Data#i WINDOW=FRONT.
  *Do stuff to the opened file
END LOOP.
EXE.

key is the only column in a file that contains all the names of the files.

I am having trouble debugging since I don't know how to print to the screen if it is possible. So my question is: is there a way to get the code above to work, or another option that accomplishes the same thing?

Was it helpful?

Solution

You can't use an expression like that on a GET command. There are two choices. Use the macro language to put this together (see DEFINE in the Command Syntax Reference via the Help menu) or use the SPSSINC PROCESS FILES extension command or your own Python code to select the files with a wildcard.

The extension command or a Python program require the free Python Essentials available from the SPSS Community website or available with your Statistics version.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top