Dear all, I have following problem: I try to write an macro (SPSS 21) which opens several spss-data-files. I have one spss-data-file which contains a string-variable (called ‘path’) in which the paths to the different data-files I want to open are saved as cases (one path per case). But I don´t know how to write a macro which uses the variable ‘path’ as a source of a dynamic element in the macro. Can anyone help me with this problem or give me a hint where I can get a answer to my question? I am a new member of this list and hope that I don´t bother you with a question which have been already answered in this community. Thanks in advance an best wishes Joachim _____________________________________________________ Joachim Globisch, M.A. Energietechnologien und Energiesysteme Fraunhofer-Institut für System- und Innovationsforschung ISI Breslauer Straße 48 | 76139 Karlsruhe Telefon +49 721 6809-483 | Fax +49 721 6809-483 Twitter: @Fraunhofer_KA YouTube: http://www.youtube.com/user/FraunhoferKA |
Administrator
|
Macros know NOTHING about the values of variables (they are expanded before any data are read).
You may want to look into python or search this forum for "horrible hack" ;-) Think of macros as basically stupid string parsers.
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" |
In reply to this post by Globisch, Joachim
Macros don't do data. Here is a Python
way to do this.
data list list/path(a100). begin data "c:\data\worldbank2001.sav" "c:\data\weibull.sav" end data. dataset name files. begin program. import spss, spssdata allfiles = spssdata.Spssdata("path").fetchall() for i, f in enumerate(allfiles): spss.Submit(r"""GET FILE="%s". DATASET NAME %s""" % (f[0], "D" + str(i))) end program. The program first gets all the values for the variable named path in the dataset named files. Then it iterates through this list and runs a GET command on each item. Since the files would be closed by opening the next one if a dataset name is not assigned, it assigns names of the form Dn where n is successive integers. Similar ideas could be used to open all the sav files in a directory or, using the SPSSINC PROCESS FILES extension command, to open all the files listed in a text file. Using PROCESS FILES would not require writing any Python code and is more general, because it can run an entire file of syntax over each file. Jon Peck (no "h") aka Kim Senior Software Engineer, IBM [hidden email] phone: 720-342-5621 From: "Globisch, Joachim" <[hidden email]> To: [hidden email], Date: 12/17/2013 06:09 AM Subject: [SPSSX-L] using string-variable-values in dynamic macros Sent by: "SPSSX(r) Discussion" <[hidden email]> Dear all, I have following problem: I try to write an macro (SPSS 21) which opens several spss-data-files. I have one spss-data-file which contains a string-variable (called ‘path’) in which the paths to the different data-files I want to open are saved as cases (one path per case). But I don´t know how to write a macro which uses the variable ‘path’ as a source of a dynamic element in the macro. Can anyone help me with this problem or give me a hint where I can get a answer to my question? I am a new member of this list and hope that I don´t bother you with a question which have been already answered in this community. Thanks in advance an best wishes Joachim _____________________________________________________ Joachim Globisch, M.A. Energietechnologien und Energiesysteme Fraunhofer-Institut für System- und Innovationsforschung ISI Breslauer Straße 48 | 76139 Karlsruhe Telefon +49 721 6809-483 | Fax +49 721 6809-483 [hidden email] http://www.isi.fraunhofer.de Twitter: @Fraunhofer_KA YouTube: http://www.youtube.com/user/FraunhoferKA |
If you don't have Python or can't install it, you can use the file names as macro argument. Use WRITE on the Path variable, use CMNEND as macro argument. write outfile = 'c:\bla.sps' /"define !path ()" /path /!enddefine Insert file = 'c:\bla.sps' Define !ActualMacro (PathName = !CMDEND) !DO !Var !IN (!PathName) Get file = !Var !DOEND !Enddefine !ActualMacro PathName = !path
|
Free forum by Nabble | Edit this page |