|
The macro below does not work but hopefully will an idea of what I am
trying achieve. What would be the correct way of setting up this macro? DEFINE !runJob (file1 !ENCLOSE ("'","'") /file2 !ENCLOSE ("'","'")) !DO !file !IN (!file1 !file2) GET FILE=!pathdat + !QUOTE('C:\Program Files\SPSS\',!file,'.sav'). FREQUENCIES ALL. !DOEND !ENDDEFINE. SET MPRINT ON. !runJob file1='Employee data' file2='cars'. SET MPRINT OFF. Many thanks in advance Jigs ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (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 |
|
Hi Jigs,
I didn't test it, but I believe this code works. It assumes that all files are located in the same dir. file handle pathdat / name = 'c:/temp/somedir/'. DEFINE !runJob (files = !cmdend) !DO !file !IN (!files) GET FILE=!QUOTE(!concat('pathdat', !file, '.sav')). FREQUENCIES ALL. !DOEND !ENDDEFINE. SET MPRINT ON. !runJob files='Employee data' 'cars'. SET MPRINT OFF. Or how about this? It runs yout analysis on ALL sav files in a given dir. import glob, spss pathdat = 'c:/temp/somedir/' savs = glob.glob(pathdat + "*.sav") def runjob (): __for k, sav in enumerate (savs): ___spss.Submit("title '** file: %s'." % sav) ___spss.Submit("get file = '%s'." % sav) ___spss.Submit("fre all.") runjob() Cheers!!! Albert-Jan ----- Original Message ---- From: J Sutar <[hidden email]> To: [hidden email] Sent: Wednesday, January 14, 2009 3:52:42 PM Subject: Loop for different file names The macro below does not work but hopefully will an idea of what I am trying achieve. What would be the correct way of setting up this macro? DEFINE !runJob (file1 !ENCLOSE ("'","'") /file2 !ENCLOSE ("'","'")) !DO !file !IN (!file1 !file2) GET FILE=!pathdat + !QUOTE('C:\Program Files\SPSS\',!file,'.sav'). FREQUENCIES ALL. !DOEND !ENDDEFINE. SET MPRINT ON. !runJob file1='Employee data' file2='cars'. SET MPRINT OFF. Many thanks in advance Jigs ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (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 [hidden email] (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 |
|
Thanks Albert-Jan,
I made a bit of a mess with the sample code I provided, sorry. Here's the the tested code that works, I just had to add in the !UNQUOTE. DEFINE !runJob (files = !cmdend) !DO !file !IN (!files) GET FILE=!QUOTE(!CONCAT('C:\Program Files\SPSS\',!UNQUOTE(!file),'.sav')). FREQUENCIES ALL. !DOEND !ENDDEFINE. SET MPRINT ON. !runJob files='Employee data' 'cars'. SET MPRINT OFF. The python solution work just as well, though I accidental ran it on all the SPSS sample files! Cheers Jigs 2009/1/14 Albert-jan Roskam <[hidden email]> > Hi Jigs, > > I didn't test it, but I believe this code works. It assumes that all files > are located in the same dir. > > file handle pathdat / name = 'c:/temp/somedir/'. > DEFINE !runJob (files = !cmdend) > !DO !file !IN (!files) > GET FILE=!QUOTE(!concat('pathdat', !file, '.sav')). > FREQUENCIES ALL. > !DOEND > !ENDDEFINE. > SET MPRINT ON. > !runJob files='Employee data' 'cars'. > SET MPRINT OFF. > > Or how about this? It runs yout analysis on ALL sav files in a given dir. > > import glob, spss > pathdat = 'c:/temp/somedir/' > savs = glob.glob(pathdat + "*.sav") > def runjob (): > __for k, sav in enumerate (savs): > ___spss.Submit("title '** file: %s'." % sav) > ___spss.Submit("get file = '%s'." % sav) > ___spss.Submit("fre all.") > runjob() > > Cheers!!! > Albert-Jan > > > ----- Original Message ---- > From: J Sutar <[hidden email]> > To: [hidden email] > Sent: Wednesday, January 14, 2009 3:52:42 PM > Subject: Loop for different file names > > The macro below does not work but hopefully will an idea of what I am > trying achieve. > What would be the correct way of setting up this macro? > > DEFINE !runJob (file1 !ENCLOSE ("'","'") /file2 !ENCLOSE ("'","'")) > !DO !file !IN (!file1 !file2) > GET FILE=!pathdat + !QUOTE('C:\Program Files\SPSS\',!file,'.sav'). > FREQUENCIES ALL. > !DOEND > !ENDDEFINE. > > SET MPRINT ON. > !runJob file1='Employee data' file2='cars'. > SET MPRINT OFF. > > Many thanks in advance > Jigs > > ===================== > To manage your subscription to SPSSX-L, send a message to > [hidden email] (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 [hidden email] (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 |
|
I like the TITLE command you have included in the program but more often
then not the path will exceed 60 characters and so SPSS will fire out warnings. So I tweaked it a little to adjust for that but it is dependent on me typing in number of characters of the root path (22 in my example below). Is it possible for the program to be adjusted so that it picks this up automatically? BEGIN PROGRAM. import glob, spss pathdat = 'C:/Program Files/SPSS/' savs = glob.glob(pathdat + "c*.sav") def runjob (): for k, sav in enumerate (savs): spss.Submit("title '** File: %s'." % sav[22:]) spss.Submit("get file = '%s'." % sav) spss.Submit("fre all.") runjob() END PROGRAM. Cheers Jigs 2009/1/14 J Sutar <[hidden email]> > Thanks Albert-Jan, > I made a bit of a mess with the sample code I provided, sorry. > > Here's the the tested code that works, I just had to add in the !UNQUOTE. > > DEFINE !runJob (files = !cmdend) > !DO !file !IN (!files) > GET FILE=!QUOTE(!CONCAT('C:\Program Files\SPSS\',!UNQUOTE(!file),'.sav')). > FREQUENCIES ALL. > !DOEND > !ENDDEFINE. > > SET MPRINT ON. > !runJob files='Employee data' 'cars'. > SET MPRINT OFF. > > > The python solution work just as well, though I accidental ran it on all > the SPSS sample files! > > Cheers > Jigs > > > > 2009/1/14 Albert-jan Roskam <[hidden email]> > > Hi Jigs, >> >> I didn't test it, but I believe this code works. It assumes that all files >> are located in the same dir. >> >> file handle pathdat / name = 'c:/temp/somedir/'. >> DEFINE !runJob (files = !cmdend) >> !DO !file !IN (!files) >> GET FILE=!QUOTE(!concat('pathdat', !file, '.sav')). >> FREQUENCIES ALL. >> !DOEND >> !ENDDEFINE. >> SET MPRINT ON. >> !runJob files='Employee data' 'cars'. >> SET MPRINT OFF. >> >> Or how about this? It runs yout analysis on ALL sav files in a given dir. >> >> import glob, spss >> pathdat = 'c:/temp/somedir/' >> savs = glob.glob(pathdat + "*.sav") >> def runjob (): >> __for k, sav in enumerate (savs): >> ___spss.Submit("title '** file: %s'." % sav) >> ___spss.Submit("get file = '%s'." % sav) >> ___spss.Submit("fre all.") >> runjob() >> >> Cheers!!! >> Albert-Jan >> >> >> ----- Original Message ---- >> From: J Sutar <[hidden email]> >> To: [hidden email] >> Sent: Wednesday, January 14, 2009 3:52:42 PM >> Subject: Loop for different file names >> >> The macro below does not work but hopefully will an idea of what I am >> trying achieve. >> What would be the correct way of setting up this macro? >> >> DEFINE !runJob (file1 !ENCLOSE ("'","'") /file2 !ENCLOSE ("'","'")) >> !DO !file !IN (!file1 !file2) >> GET FILE=!pathdat + !QUOTE('C:\Program Files\SPSS\',!file,'.sav'). >> FREQUENCIES ALL. >> !DOEND >> !ENDDEFINE. >> >> SET MPRINT ON. >> !runJob file1='Employee data' file2='cars'. >> SET MPRINT OFF. >> >> Many thanks in advance >> Jigs >> >> ===================== >> To manage your subscription to SPSSX-L, send a message to >> [hidden email] (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 [hidden email] (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 |
|
-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of J Sutar Sent: Wednesday, January 14, 2009 10:04 AM To: [hidden email] Subject: Re: [SPSSX-L] Loop for different file names I like the TITLE command you have included in the program but more often then not the path will exceed 60 characters and so SPSS will fire out warnings. So I tweaked it a little to adjust for that but it is dependent on me typing in number of characters of the root path (22 in my example below). Is it possible for the program to be adjusted so that it picks this up automatically? BEGIN PROGRAM. import glob, spss pathdat = 'C:/Program Files/SPSS/' savs = glob.glob(pathdat + "c*.sav") def runjob (): for k, sav in enumerate (savs): spss.Submit("title '** File: %s'." % sav[22:]) spss.Submit("get file = '%s'." % sav) spss.Submit("fre all.") runjob() END PROGRAM. Cheers Jigs [>>>Peck, Jon] Here's another version. BEGIN PROGRAM. import glob, spss, os def runjob (savs): for sav in savs: spss.Submit("title '** File: %s'." % os.path.basename(sav)) spss.Submit("get file = '%s'." % sav) spss.Submit("fre all.") pathdat = 'C:/Program Files/SPSS/' runjob() END PROGRAM. Regards, Jon Peck p.s. The spssaux3.py module on Developer Central has a general function, ApplySyntaxToFiles, that will run through a wildcard-specified file list and run syntax against them with various options for handling the display output or modified sav files and logging. 2009/1/14 J Sutar <[hidden email]> > Thanks Albert-Jan, > I made a bit of a mess with the sample code I provided, sorry. > > Here's the the tested code that works, I just had to add in the !UNQUOTE. > > DEFINE !runJob (files = !cmdend) > !DO !file !IN (!files) > GET FILE=!QUOTE(!CONCAT('C:\Program Files\SPSS\',!UNQUOTE(!file),'.sav')). > FREQUENCIES ALL. > !DOEND > !ENDDEFINE. > > SET MPRINT ON. > !runJob files='Employee data' 'cars'. > SET MPRINT OFF. > > > The python solution work just as well, though I accidental ran it on all > the SPSS sample files! > > Cheers > Jigs > > > > 2009/1/14 Albert-jan Roskam <[hidden email]> > > Hi Jigs, >> >> I didn't test it, but I believe this code works. It assumes that all files >> are located in the same dir. >> >> file handle pathdat / name = 'c:/temp/somedir/'. >> DEFINE !runJob (files = !cmdend) >> !DO !file !IN (!files) >> GET FILE=!QUOTE(!concat('pathdat', !file, '.sav')). >> FREQUENCIES ALL. >> !DOEND >> !ENDDEFINE. >> SET MPRINT ON. >> !runJob files='Employee data' 'cars'. >> SET MPRINT OFF. >> >> Or how about this? It runs yout analysis on ALL sav files in a given dir. >> >> import glob, spss >> pathdat = 'c:/temp/somedir/' >> savs = glob.glob(pathdat + "*.sav") >> def runjob (): >> __for k, sav in enumerate (savs): >> ___spss.Submit("title '** file: %s'." % sav) >> ___spss.Submit("get file = '%s'." % sav) >> ___spss.Submit("fre all.") >> runjob() >> >> Cheers!!! >> Albert-Jan >> >> >> ----- Original Message ---- >> From: J Sutar <[hidden email]> >> To: [hidden email] >> Sent: Wednesday, January 14, 2009 3:52:42 PM >> Subject: Loop for different file names >> >> The macro below does not work but hopefully will an idea of what I am >> trying achieve. >> What would be the correct way of setting up this macro? >> >> DEFINE !runJob (file1 !ENCLOSE ("'","'") /file2 !ENCLOSE ("'","'")) >> !DO !file !IN (!file1 !file2) >> GET FILE=!pathdat + !QUOTE('C:\Program Files\SPSS\',!file,'.sav'). >> FREQUENCIES ALL. >> !DOEND >> !ENDDEFINE. >> >> SET MPRINT ON. >> !runJob file1='Employee data' file2='cars'. >> SET MPRINT OFF. >> >> Many thanks in advance >> Jigs >> >> ===================== >> To manage your subscription to SPSSX-L, send a message to >> [hidden email] (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 [hidden email] (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 [hidden email] (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 |
|
oops below.
-----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Peck, Jon Sent: Wednesday, January 14, 2009 10:28 AM To: [hidden email] Subject: Re: [SPSSX-L] Loop for different file names -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of J Sutar Sent: Wednesday, January 14, 2009 10:04 AM To: [hidden email] Subject: Re: [SPSSX-L] Loop for different file names I like the TITLE command you have included in the program but more often then not the path will exceed 60 characters and so SPSS will fire out warnings. So I tweaked it a little to adjust for that but it is dependent on me typing in number of characters of the root path (22 in my example below). Is it possible for the program to be adjusted so that it picks this up automatically? BEGIN PROGRAM. import glob, spss pathdat = 'C:/Program Files/SPSS/' savs = glob.glob(pathdat + "c*.sav") def runjob (): for k, sav in enumerate (savs): spss.Submit("title '** File: %s'." % sav[22:]) spss.Submit("get file = '%s'." % sav) spss.Submit("fre all.") runjob() END PROGRAM. Cheers Jigs [>>>Peck, Jon] Here's another version. BEGIN PROGRAM. import glob, spss, os def runjob (savs): for sav in savs: spss.Submit("title '** File: %s'." % os.path.basename(sav)) spss.Submit("get file = '%s'." % sav) spss.Submit("fre all.") # corrected... pathdat = 'C:/Program Files/SPSS/' savs = glob.glob(pathdat + "c*.sav") runjob(savs) END PROGRAM. Regards, Jon Peck p.s. The spssaux3.py module on Developer Central has a general function, ApplySyntaxToFiles, that will run through a wildcard-specified file list and run syntax against them with various options for handling the display output or modified sav files and logging. 2009/1/14 J Sutar <[hidden email]> > Thanks Albert-Jan, > I made a bit of a mess with the sample code I provided, sorry. > > Here's the the tested code that works, I just had to add in the !UNQUOTE. > > DEFINE !runJob (files = !cmdend) > !DO !file !IN (!files) > GET FILE=!QUOTE(!CONCAT('C:\Program Files\SPSS\',!UNQUOTE(!file),'.sav')). > FREQUENCIES ALL. > !DOEND > !ENDDEFINE. > > SET MPRINT ON. > !runJob files='Employee data' 'cars'. > SET MPRINT OFF. > > > The python solution work just as well, though I accidental ran it on all > the SPSS sample files! > > Cheers > Jigs > > > > 2009/1/14 Albert-jan Roskam <[hidden email]> > > Hi Jigs, >> >> I didn't test it, but I believe this code works. It assumes that all files >> are located in the same dir. >> >> file handle pathdat / name = 'c:/temp/somedir/'. >> DEFINE !runJob (files = !cmdend) >> !DO !file !IN (!files) >> GET FILE=!QUOTE(!concat('pathdat', !file, '.sav')). >> FREQUENCIES ALL. >> !DOEND >> !ENDDEFINE. >> SET MPRINT ON. >> !runJob files='Employee data' 'cars'. >> SET MPRINT OFF. >> >> Or how about this? It runs yout analysis on ALL sav files in a given dir. >> >> import glob, spss >> pathdat = 'c:/temp/somedir/' >> savs = glob.glob(pathdat + "*.sav") >> def runjob (): >> __for k, sav in enumerate (savs): >> ___spss.Submit("title '** file: %s'." % sav) >> ___spss.Submit("get file = '%s'." % sav) >> ___spss.Submit("fre all.") >> runjob() >> >> Cheers!!! >> Albert-Jan >> >> >> ----- Original Message ---- >> From: J Sutar <[hidden email]> >> To: [hidden email] >> Sent: Wednesday, January 14, 2009 3:52:42 PM >> Subject: Loop for different file names >> >> The macro below does not work but hopefully will an idea of what I am >> trying achieve. >> What would be the correct way of setting up this macro? >> >> DEFINE !runJob (file1 !ENCLOSE ("'","'") /file2 !ENCLOSE ("'","'")) >> !DO !file !IN (!file1 !file2) >> GET FILE=!pathdat + !QUOTE('C:\Program Files\SPSS\',!file,'.sav'). >> FREQUENCIES ALL. >> !DOEND >> !ENDDEFINE. >> >> SET MPRINT ON. >> !runJob file1='Employee data' file2='cars'. >> SET MPRINT OFF. >> >> Many thanks in advance >> Jigs >> >> ===================== >> To manage your subscription to SPSSX-L, send a message to >> [hidden email] (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 [hidden email] (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 [hidden email] (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 [hidden email] (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 |
| Free forum by Nabble | Edit this page |
