SPSS Statistics

SPSS Statistics

Your hub for statistical analysis, data management, and data documentation. Connect, learn, and share with your peers! 

 View Only

Searching SPSS Case Data: An Enhancement to the SPSSINC PROCESS FILES Extension Command

By Archive User posted Wed March 31, 2010 05:07 PM

  


I recently posted a new extension command, SPSSINC PROCESS FILES (along with SPSSINC SPLIT DATASET). The command applies a syntax file to a set of files.  Recently someone asked for a way to search across the case data in many data files to find a particular ID value. This can be done with SPSSINC PROCESS FILES, but it occurred to me that a few enhancements to the command would simplify this process. This new version is the results.  Another extension command, GATHERMD, can collect variable names and labels across data files into a single dataset, making it easy to search that metadata, but it does not look at the case data.



Note: Updated again to reflect more improvements to the case data searching user interface and syntax.




PROCESS files requires at a minimum an input specification, perhaps a wildcard expression, to select the files to process, a syntax file to apply to them, and maybe some output specifications.  The awkwardness in using this for search is the need to edit the syntax file every time you have a different search specification.  (File names and such are already provided for by file handles and macros.)  My thought was to fix this by adding a way for users to define macro expressions using PROCESS FILES.  There is now a new subcommand, MACROVALUES, with a set of keywords to define macro expressions, and there is an accompanying subdialog box for the command.



 



Using this feature, you could create a single syntax file that finds the cases according to specified criteria and lists the results.  Macro parameters are used to pass the search criteria to the syntax file.  A search syntax file is now included in the package.  You can look at that file in the package or by using the dialog box help, so I won't list it here. To use it, you would run a command like this.



SPSSINC PROCESS FILES INPUTDATA="c:\spss18\samples\english\e*.sav"

SYNTAX="some location\searchfiles.sps" CONTINUEONERROR=YES

VIEWERFILE= "c:/temp/outputfiles/searchresults.spv" CLOSEDATA=YES

MACRONAME="!JOB" LOGFILEMODE=OVERWRITE

/MACRODEFS ITEMS PARM1="ID >= 100 and ID <110" PARM2="ID" PARM3="educ salary".




  • PARM1 defines the cases you want to find.


  • PARM2 names the case id variable for display purposes.


  • PARM3 names any other variables that should be listed.



You need to list at least one variable in either PARM2 or PARM3.



This is quite general: the expression defining the cases you are looking for can be any SPSS logical expression, and if variables don't exist in a file being searched or there are no matches in the cases, everything is quietly tidied up for you.  If you specify a single Viewer file for all the output as in the example above, the result is a file with a table listing the matching cases for each input data file.



Update: Macro parameters can be very useful, but for searching in particular, a simpler user interface would be useful.  I have added a keyword SEARCH=YES|NO, and if you choose YES, you omit the syntax file, and the command takes care of the details.  To make this easier to use, I have created a search-specific dialog box that generates the appropriate syntax.  It is simplified a lot to remove options that are probably not particularly useful for searching, and it labels the required fields with their purpose rather than using terms like PARM1.  This is pretty easy to do, so if you have a specialized task to do, you could adapt the dialog box text accordingly.  As part of the search improvements, I have eliminated the separate syntax file for searching, since this is now built into the command.



I created SPSSINC PROCESS FILES originally having in mind examples of batch processing of similar sets of files.  Realizing that it could also provide a cross-file data search was a serendipitous extra.



The new version is now available on SPSS Developer Central.  Feedback is welcome.  As with the earlier version, the command requires at least SPSS Statistics Version 17 and the Python programmability plugin.








#extensions
#Programmability
#python
#SPSSStatistics
0 comments
1 view

Permalink