LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (July 2006)Back to main SPSSX-L pageJoin or leave SPSSX-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
=========================================================================
Date:         Tue, 25 Jul 2006 15:35:19 -0500
Reply-To:     "Hearne, Marcus" <mhearne@spss.com>
Sender:       "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From:         "Hearne, Marcus" <mhearne@spss.com>
Subject:      Re: Saving file as part of python program
Content-Type: text/plain; charset="us-ascii"

Greetings,

This thread has been cross-posted by John Bauer to the SPSS Developer Forums at SPSS Developer Central (http://www.spss.com/devcentral/). It can be found in the Python discussion forum under the topic "Open all files matching a pattern, save with new name".

This will allow users of SPSS Developer Central to more easily locate and benefit from the solution, and contribute alternatives.

We hope that the forums there will become the first stop for those using Python and SPSS Programmability, allowing the X-list to return to its regularly scheduled content. SPSS Developer Central has many benefits including input directly from the SPSS Programmability team and detailed solutions including sample code.

Regards, Marcus Hearne Sr. Product Manager SPSS Inc.

-----Original Message----- From: SPSSX(r) Discussion [mailto:SPSSX-L@LISTSERV.UGA.EDU] On Behalf Of Bauer, John H. Sent: Monday, July 24, 2006 4:45 PM To: SPSSX-L@LISTSERV.UGA.EDU Subject: Re: Saving file as part of python program

Robert,

Sorry I don't have time to explain the changes, the main point is that you weren't substituting outfile into the syntax. Also note that glob1 searches on path, pattern making it easier to work with the results for your purposes. Try something more like this:

Begin Program. import spss, glob, spssaux path = 'c:/temp/' pattern = '*.sav' savlist=glob.glob1(path, pattern) for basefile in savlist: outfile=path + 'nu' + basefile spssaux.OpenDataFile(path + basefile) spss.Submit("""compute test=10 . save outfile='%s' /compressed.""" % outfile) End Program.

-----Original Message----- From: SPSSX(r) Discussion [mailto:SPSSX-L@LISTSERV.UGA.EDU] On Behalf Of Roberts, Michael Sent: Monday, July 24, 2006 3:29 PM To: SPSSX-L@LISTSERV.UGA.EDU Subject: Saving file as part of python program

Hi all,

Would someone be able to look at this code and let me know what is wrong? I have tried several approaches, and although the files opened up, the code apparently works only on the last file opened, and then does not save it.

I selected a small sample of 5 spss formatted files in a folder to test the program, which is supposed to open the files one by one, perform an spss function - in this case, select the first ten cases, then save the file with the 'nu' in front of the old file name.

I would appreciate any help you can provide with this, as none of the documentation seems to address how to do this cyclical processing.

set printback on mprint on. Begin Program. import spss, glob, spssaux savlist=glob.glob('c:/path/proj_test/tst*.sav') for basefile in savlist: outfile='nu'+ basefile spssaux.OpenDataFile(basefile) spss.Submit("""compute test=10*var_1. save outfile='c:/path/proj_test/outfile' /compressed.""") End Program.

Thanks in Advance

Mike

-----Original Message----- From: SPSSX(r) Discussion [mailto:SPSSX-L@LISTSERV.UGA.EDU] On Behalf Of John Norton Sent: Monday, July 24, 2006 4:03 PM To: SPSSX-L@LISTSERV.UGA.EDU Subject: Re: Make bold or in color sign. correlations in output

Hi List:

I wanted to add a caveat (or a "gotcha") to James Parry's reference to the 'Correlations_Table_Correlations_Create' script. This is quite a useful script, but when running correlations from command language and using the WITH statement, this script will still remove the diagonal and the upper half of the matrix, regardless of the WITH statement.

So, for example, if you execute correlations from the dialogs with variables q1 q2 and q3, you'll get a matrix with variables q1 q2 and q3 defining both the rows and the columns. So, in the diagonal, you'll get perfect correlations - as variables tend to do with themselves - and in the upper right corner half of the table you'll get identical correlations as you would with the variable combinations in the lower left half of the matrix. In this case, it makes sense that the diagonals of correlations of variables with themselves, and the redundant upper corner half of the matrix be removed.

But if you use command language with the WITH statement:

CORRELATIONS /VARIABLES=x1 x2 x3 WITH x4 x5 x6 /PRINT=TWOTAIL NOSIG /MISSING=PAIRWISE .

..you'll get a matrix with variables x1 x2 and x3 defining the rows and variables x4 x5 and x6 defining the columns. The script will still remove the diagonal and the upper right corner half of the matrix, regardless of the fact that in this case, there are no redundancies.

This is more of an annoyance and a speed bump than anything else (especially if/when attempting to demonstrate correlations in class, and after forgetting that you've already demonstrated this script and left it active). Still, it's a "gotcha" to be aware of - it's always a good idea to monitor what you automate. :-)

Best,

John Norton Biostatistician Oncology Institute Loyola University Medical Center

(708) 327-3095 jnorton@lumc.edu

"Absence of evidence is not evidence of absence"

>>> "Parry, James" <jparry@spss.com> 7/24/2006 2:15 PM >>>

Hi Martin (and list!),

There is a script that comes with SPSS called 'Correlations_Table_Correlations_Create' that 1) omits the top part of the diagonal of the correlation matrix and b) highlights in yellow any significant correlations (to .01, 2-tailed).

The way to activate the autoscript is to go to Edit...Options, choose the Scripts Tab and make sure to select the second script down 'Correlations_Table_Correlations_Create'. After selecting the script, make sure to press OK, and then run correlations.

Also, if you're interested in altering any of the parameters (say significance level to be highlighted, color of highlighting or font, etc.), or if you want to make the script work for Spearman's, here is a link to an earlier, detailed explanation by one of SPSS' Statisticians:

http://www.listserv.uga.edu/cgi-bin/wa?A2=ind9811&L=spssx-l&P=2898

If anyone happens to have a version of this script in another language (Python, VB, etc.) please feel free to submit it to: http://www.spss.com/devcentral/, our new meeting place for SPSS'ers interested in powerful statistical development.

Best,

James E. Parry


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