|
Dear all,
I have a syntax which needs to be automated via macro. I wish to select cases from the variable month which is populated by 01,02,03,04,05,06,07,08,09,10,11,12 and save them as 200701jan.sav,200702feb.sav,200703mar.sav,,,,,,200712dec,,,,respectively, where the data 200701jan.sav is only populated by cases where month=01.. and so on. I tried this ,but it pops up errors which I fail to comprehend. DEFINE !a (select=!CHAREND('/')). !let !m=!SUBSTR(!s,1,2). !let !p=!substr(!s,3,9). !DO !s !IN (!select) get file ='C:\indata01.sav'. select if month =!quote(!m). save outfile = !QUOTE(!CONCAT('C:\FTS_MZ\indata01',!substr(!p,1,2),'.sav')). !DOEND. !ENDDEFINE. !a select = 01200701jan 02200702feb 03200703mar /. I need your help. thanks, Samuel. ====================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 Samuel
try the following syntax. Hope this helps. Christian ******************************* la volta statistics Christian Schmidhauser, Dr.phil.II Weinbergstrasse 108 Ch-8006 Zürich Tel: +41 (043) 233 98 01 Fax: +41 (043) 233 98 02 email: mailto:[hidden email] internet: http://www.lavolta.ch/ New File. Dataset close all. DEFINE !a (select = !CHAREND('/')). !DO !i !IN (!select). !let !m=!SUBSTR(!i,2,2). !let !Path = !QUOTE(!CONCAT("C:\FTS_MZ\indata01",!substr(!i,4,9),".sav")). *Echo !PAth. get file ='C:\indata01\indata01.sav'. select if month =!quote(!m). save outfile = !Path. !DOEND. !ENDDEFINE. !a select = '01200701jan' '02200702feb' '03200703mar' /. -----Ursprüngliche Nachricht----- Von: SPSSX(r) Discussion [mailto:[hidden email]]Im Auftrag von Samuel Solomon Gesendet: Donnerstag, 20. Dezember 2007 09:33 An: [hidden email] Betreff: automating syntax Dear all, I have a syntax which needs to be automated via macro. I wish to select cases from the variable month which is populated by 01,02,03,04,05,06,07,08,09,10,11,12 and save them as 200701jan.sav,200702feb.sav,200703mar.sav,,,,,,200712dec,,,,respectively, where the data 200701jan.sav is only populated by cases where month=01.. and so on. I tried this ,but it pops up errors which I fail to comprehend. DEFINE !a (select=!CHAREND('/')). !let !m=!SUBSTR(!s,1,2). !let !p=!substr(!s,3,9). !DO !s !IN (!select) get file ='C:\indata01.sav'. select if month =!quote(!m). save outfile = !QUOTE(!CONCAT('C:\FTS_MZ\indata01',!substr(!p,1,2),'.sav')). !DOEND. !ENDDEFINE. !a select = 01200701jan 02200702feb 03200703mar /. I need your help. thanks, Samuel. ======= 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 |
|
Dear Christian,
Thanks it works but could you make it any general? Can I call different files in the 'get file' command at the same time. could you do it any other way. thanks ________________________________ From: SPSSX(r) Discussion on behalf of la volta statistics Sent: Thu 12/20/2007 5:10 PM To: [hidden email] Subject: AW: automating syntax Hi Samuel try the following syntax. Hope this helps. Christian ******************************* la volta statistics Christian Schmidhauser, Dr.phil.II Weinbergstrasse 108 Ch-8006 Zürich Tel: +41 (043) 233 98 01 Fax: +41 (043) 233 98 02 email: mailto:[hidden email] internet: http://www.lavolta.ch/ New File. Dataset close all. DEFINE !a (select = !CHAREND('/')). !DO !i !IN (!select). !let !m=!SUBSTR(!i,2,2). !let !Path = !QUOTE(!CONCAT("C:\FTS_MZ\indata01",!substr(!i,4,9),".sav")). *Echo !PAth. get file ='C:\indata01\indata01.sav'. select if month =!quote(!m). save outfile = !Path. !DOEND. !ENDDEFINE. !a select = '01200701jan' '02200702feb' '03200703mar' /. -----Ursprüngliche Nachricht----- Von: SPSSX(r) Discussion [mailto:[hidden email]]Im Auftrag von Samuel Solomon Gesendet: Donnerstag, 20. Dezember 2007 09:33 An: [hidden email] Betreff: automating syntax Dear all, I have a syntax which needs to be automated via macro. I wish to select cases from the variable month which is populated by 01,02,03,04,05,06,07,08,09,10,11,12 and save them as 200701jan.sav,200702feb.sav,200703mar.sav,,,,,,200712dec,,,,respectively, where the data 200701jan.sav is only populated by cases where month=01.. and so on. I tried this ,but it pops up errors which I fail to comprehend. DEFINE !a (select=!CHAREND('/')). !let !m=!SUBSTR(!s,1,2). !let !p=!substr(!s,3,9). !DO !s !IN (!select) get file ='C:\indata01.sav'. select if month =!quote(!m). save outfile = !QUOTE(!CONCAT('C:\FTS_MZ\indata01',!substr(!p,1,2),'.sav')). !DOEND. !ENDDEFINE. !a select = 01200701jan 02200702feb 03200703mar /. I need your help. thanks, Samuel. ======= 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 |
|
Assuming your month variable is numeric and has value labels, here is a python solution - if your month variable is string, you can easily convert it to numeric and add labels.
BEGIN PROGRAM. import spss, spssaux """Opens an spss file with specified name. Assuming there is a variable labeled 'month' with value labels for numeric values that represent month (i.e., 1 = jan, 2 = feb, etc), saves one file per month that contains only that month's data with the naming convention - 4-digit year, two digit month, and text month""" spss.Submit(r"get file 'C:\test_3.sav'.") var = 'month' twodigit = ['10', '11', '12'] vlabels = spssaux.getValueLabels(0) for k, v in vlabels.iteritems(): if k not in twodigit: spss.Submit("""temporary. select if (%s = %s). save outfile 'c:/20070%s%s.sav'.""" %(var,k,k,v)) else: spss.Submit("""temporary. select if (%s = %s). save outfile 'c:/2007%s%s.sav'.""" %(var,k,k,v)) END PROGRAM. -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Samuel Solomon Sent: Thursday, December 20, 2007 9:53 AM To: [hidden email] Subject: Re: AW: automating syntax Dear Christian, Thanks it works but could you make it any general? Can I call different files in the 'get file' command at the same time. could you do it any other way. thanks ________________________________ From: SPSSX(r) Discussion on behalf of la volta statistics Sent: Thu 12/20/2007 5:10 PM To: [hidden email] Subject: AW: automating syntax Hi Samuel try the following syntax. Hope this helps. Christian ******************************* la volta statistics Christian Schmidhauser, Dr.phil.II Weinbergstrasse 108 Ch-8006 Zürich Tel: +41 (043) 233 98 01 Fax: +41 (043) 233 98 02 email: mailto:[hidden email] internet: http://www.lavolta.ch/ New File. Dataset close all. DEFINE !a (select = !CHAREND('/')). !DO !i !IN (!select). !let !m=!SUBSTR(!i,2,2). !let !Path = !QUOTE(!CONCAT("C:\FTS_MZ\indata01",!substr(!i,4,9),".sav")). *Echo !PAth. get file ='C:\indata01\indata01.sav'. select if month =!quote(!m). save outfile = !Path. !DOEND. !ENDDEFINE. !a select = '01200701jan' '02200702feb' '03200703mar' /. -----Ursprüngliche Nachricht----- Von: SPSSX(r) Discussion [mailto:[hidden email]]Im Auftrag von Samuel Solomon Gesendet: Donnerstag, 20. Dezember 2007 09:33 An: [hidden email] Betreff: automating syntax Dear all, I have a syntax which needs to be automated via macro. I wish to select cases from the variable month which is populated by 01,02,03,04,05,06,07,08,09,10,11,12 and save them as 200701jan.sav,200702feb.sav,200703mar.sav,,,,,,200712dec,,,,respectively, where the data 200701jan.sav is only populated by cases where month=01.. and so on. I tried this ,but it pops up errors which I fail to comprehend. DEFINE !a (select=!CHAREND('/')). !let !m=!SUBSTR(!s,1,2). !let !p=!substr(!s,3,9). !DO !s !IN (!select) get file ='C:\indata01.sav'. select if month =!quote(!m). save outfile = !QUOTE(!CONCAT('C:\FTS_MZ\indata01',!substr(!p,1,2),'.sav')). !DOEND. !ENDDEFINE. !a select = 01200701jan 02200702feb 03200703mar /. I need your help. thanks, Samuel. ======= 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 No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.503 / Virus Database: 269.17.5/1190 - Release Date: 12/19/2007 7:37 PM No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.5.503 / Virus Database: 269.17.5/1190 - Release Date: 12/19/2007 7:37 PM ===================== 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 |
|
In reply to this post by Samuel Solomon
Hi Samuel
You are not particularly specific about what you want. Of course can the get file command be changed. You also can have different data file open when you have SPSS v14 (I think) or higher. You then need to set the the fiel active you want to work with. Look up Dataset ACTIVAte in the help. If you want to call it through a macro argument, you need to make a path such as you have it now for the save command. Use the Echo command to test your macro. I left you the Echo command in the macro as an example (*Echo !Path). Eventually you need to use the: New File. Dataset close all. after each saving. Hope this helps, Christian * Start with something like that: DEFINE !a (select = !CHAREND('/')). !DO !i !IN (!select). !let !GPath =.(write here the path and the name of the file) *Echo !GPAth. get file =!GPAth.. !DOEND. !ENDDEFINE. !a select = '01200701jan' '02200702feb' '03200703mar' /. -----Ursprüngliche Nachricht----- Von: SPSSX(r) Discussion [mailto:[hidden email]]Im Auftrag von Samuel Solomon Gesendet: Donnerstag, 20. Dezember 2007 15:53 An: [hidden email] Betreff: Re: AW: automating syntax Dear Christian, Thanks it works but could you make it any general? Can I call different files in the 'get file' command at the same time. could you do it any other way. thanks ________________________________ From: SPSSX(r) Discussion on behalf of la volta statistics Sent: Thu 12/20/2007 5:10 PM To: [hidden email] Subject: AW: automating syntax Hi Samuel try the following syntax. Hope this helps. Christian ******************************* la volta statistics Christian Schmidhauser, Dr.phil.II Weinbergstrasse 108 Ch-8006 Zürich Tel: +41 (043) 233 98 01 Fax: +41 (043) 233 98 02 email: mailto:[hidden email] internet: http://www.lavolta.ch/ New File. Dataset close all. DEFINE !a (select = !CHAREND('/')). !DO !i !IN (!select). !let !m=!SUBSTR(!i,2,2). !let !Path = !QUOTE(!CONCAT("C:\FTS_MZ\indata01",!substr(!i,4,9),".sav")). *Echo !PAth. get file ='C:\indata01\indata01.sav'. select if month =!quote(!m). save outfile = !Path. !DOEND. !ENDDEFINE. !a select = '01200701jan' '02200702feb' '03200703mar' /. -----Ursprüngliche Nachricht----- Von: SPSSX(r) Discussion [mailto:[hidden email]]Im Auftrag von Samuel Solomon Gesendet: Donnerstag, 20. Dezember 2007 09:33 An: [hidden email] Betreff: automating syntax Dear all, I have a syntax which needs to be automated via macro. I wish to select cases from the variable month which is populated by 01,02,03,04,05,06,07,08,09,10,11,12 and save them as 200701jan.sav,200702feb.sav,200703mar.sav,,,,,,200712dec,,,,respectively, where the data 200701jan.sav is only populated by cases where month=01.. and so on. I tried this ,but it pops up errors which I fail to comprehend. DEFINE !a (select=!CHAREND('/')). !let !m=!SUBSTR(!s,1,2). !let !p=!substr(!s,3,9). !DO !s !IN (!select) get file ='C:\indata01.sav'. select if month =!quote(!m). save outfile = !QUOTE(!CONCAT('C:\FTS_MZ\indata01',!substr(!p,1,2),'.sav')). !DOEND. !ENDDEFINE. !a select = 01200701jan 02200702feb 03200703mar /. I need your help. thanks, Samuel. ======= 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 |
