Date: Fri, 23 May 2008 10:57:01 -0500 Reply-To: "Peck, Jon" Sender: "SPSSX(r) Discussion" From: "Peck, Jon" Subject: Re: request for PYTHON to stack (pool) variable views from a list of files into a system files Comments: To: Art@DrKendall.org In-Reply-To: A<4836E7C8.7030105@DrKendall.org> Content-Type: text/plain; charset="UTF-8" Art, Take a look at APPLY DICTIONARY. It allows you to copy a variable dictionary – selected properties or all – to a new data file. We enhanced this command a few releases back in part to make it easy to use a sav file as a template for a new file. That does not deal with the looping part, but if you loop over a bunch of files and just keep using APPLY DICTIONARY to transfer the variable information to the same dataset, you are done. Regards, Jon -----Original Message----- From: SPSSX(r) Discussion [mailto:SPSSX-L@LISTSERV.UGA.EDU] On Behalf Of Art Kendall Sent: Friday, May 23, 2008 9:51 AM To: SPSSX-L@LISTSERV.UGA.EDU Subject: [SPSSX-L] request for PYTHON to stack (pool) variable views from a list of files into a system files Earlier I posted a similar request and received from users a macro/OMS approach and an excel macro approach which I will try this weekend if I cannot get a PYTHON approach. However, I thought this would be a natural for PYTHON and might be useful for many users, so I am making another request. I realized that part of my problem might be that I asked for all of the columns from the variable view and this might be problematic for missing values and value labels. Now I am making a simpler request asking only for a 4 column data file. source_file position variable_name variable_label and could get by with just 3 columns. and later use LAG to get the position. source_file position variable_name variable_label *One approach* would be to by PYTHON read a list of filenames from a file open a target SPSS file for each file bring it into SPSS put the needed variables from the variables view into the target file next file. save the target file. *Another approach *would be for to write syntax either directly or via macro that opens the target file then for each file bring the file in then do some python magic to write the info to the target file next file. save the target file. this is an idea of that approach. *Then the question is what to put into the file* 'd:\project\python_stuff.abc'. dataset declare target. GET SAS DATA='D:\project\2004\Alabama.sas7bdat'. dataset name source. string source_file (a60). compute source_file = 'D:\project\2004\Alabama.sas7bdat'. insert 'd:\project\python_stuff.abc'. dataset close source. GET SAS DATA='D:\project\2204\Alaska.sas7bdat'. dataset name source. string source_file (a60). compute source_file = 'D:\project\2004\Alaska.sas7bdat'. insert 'd:\project\python_stuff.abc'. dataset close source. . . . GET SAS DATA='D:\project\2004\West Virginia.sas7bdat'. dataset name source. string source_file (a60). compute source_file = 'D:\project\2004\West Virginia.sas7bdat'. insert 'd:\project\python_stuff.abc'. dataset close source. dataset activate target. save outfile= 'd:\project\big dictionary.sav'. - - - - In the long run it would be handy if SPSS were enhanced so that in variable view one could do . It would be even better if there were a syntax way to save the variable view to a data file. Art Kendall Social Research Consultants Celebrating the 60th Anniversary of the UN's*/ Universal Declaration of Human Rights/* ===================== To manage your subscription to SPSSX-L, send a message to LISTSERV@LISTSERV.UGA.EDU (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD ===================== To manage your subscription to SPSSX-L, send a message to LISTSERV@LISTSERV.UGA.EDU (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD 

Back to: Top of message | Previous page | Main SPSSX-L page