|
Is there a way to save a variable name in a Save file name. For instance, if I have: DATA LIST LIST /day month year ABC. BEGIN DATA 1 2 2002 1 14 1 2003 0 5 2 2004 1 9 2 2007 1 END DATA. Can I create a Save Translate to Excel with “ABC” in its name because it’s V4. In the end I would like a file named 'C:\Desktop\Management_Index – ABC.xls’ and if I changed V4, the Excel file name would change. Thanks, Keith Howey Evaluation Associate Common Ground Community 505 8th Avenue, 12th Floor New York, NY 10018 (212) 389-9383
|
|
This sort of thing requires the Python
Essentials. If you have installed these, you can do it this way.
begin program. import spss varname = spss.GetVariableName(3) spss.Submit(r"""SAVE TRANSLATE /OUTFILE="C:\Desktop\Management_Index – %s.xls" ...""" % varname) end program. Variable indexes count from 0 in Python. Replace the ... with whatever other SAVE TRANSLATE syntax is required. The %s will be replace by the name of the 4th variable. HTH, Jon Peck (no "h") aka Kim Senior Software Engineer, IBM [hidden email] new phone: 720-342-5621 From: Keith Howey <[hidden email]> To: [hidden email] Date: 03/08/2012 10:03 AM Subject: [SPSSX-L] Using a variable or cell in a Save file name Sent by: "SPSSX(r) Discussion" <[hidden email]> Is there a way to save a variable name in a Save file name. For instance, if I have: DATA LIST LIST /day month year ABC. BEGIN DATA 1 2 2002 1 14 1 2003 0 5 2 2004 1 9 2 2007 1 END DATA. Can I create a Save Translate to Excel with “ABC” in its name because it’s V4. In the end I would like a file named 'C:\Desktop\Management_Index – ABC.xls’ and if I changed V4, the Excel file name would change. Thanks, Keith Howey Evaluation Associate Common Ground Community 505 8th Avenue, 12th Floor New York, NY 10018 (212) 389-9383 khowey@...
|
|
Administrator
|
I know Jon dislikes this approach very much, but here's another way to do it that does not require Python. ;-)
* Read in the sample data. DATA LIST LIST /day month year ABC. BEGIN DATA 1 2 2002 1 14 1 2003 0 5 2 2004 1 9 2 2007 1 END DATA. dataset name f1. DATASET DECLARE f2. OMS /SELECT TABLES /IF COMMANDS=['File Information'] SUBTYPES=['Variable Information'] /DESTINATION FORMAT=SAV NUMBERED=tnum OUTFILE='f2'. display dictionary. OMSEND. dataset activate f2. compute case = $casenum. execute. /* A case where EXECUTE is needed! . select if case EQ 4. /* Select the 4th variable. execute. alter type Var1(amin). /* Var1 holds the variable name. write outfile = "C:\Temp\save file.sps" / "SAVE TRANSLATE OUTFILE='C:\Temp\Management_Index – ", Var1, ".xls'" / " /TYPE=XLS" / " /VERSION=2" / " /MAP" / " /REPLACE" / " /FIELDNAMES." . execute. dataset activate f1. INSERT FILE = "C:\Temp\save file.sps". dataset close f2.
--
Bruce Weaver bweaver@lakeheadu.ca http://sites.google.com/a/lakeheadu.ca/bweaver/ "When all else fails, RTFM." PLEASE NOTE THE FOLLOWING: 1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above. 2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/). |
|
Administrator
|
I dislike this approach very much too ;-)
OTOH: I'm the one who first introduced it about 20 years ago! So, while we are here, for old times: I'll see JoNoH's Python and Your OMS and *RAISE* you a FLIP!!!! N.B. Could use INSERT rather than INCLUDE and diddle the DATA SET biz rather than SAVE if that floats your boat ;-)))) ---- DATA LIST FREE/day month year ABC. BEGIN DATA 1 2 2002 1 14 1 2003 0 5 2 2004 1 9 2 2007 1 END DATA. SAVE OUTFILE "blah.sav". SELECT IF $CASENUM=1. FLIP. DO IF ($CASENUM=4). write outfile = "C:\Temp\save file.sps" / "SAVE TRANSLATE OUTFILE='C:\Temp\Management_Index – ", CASE_LBL , ".xls'" / " /TYPE=XLS /VERSION=2/MAP/REPLACE/FIELDNAMES.". END IF. EXE. GET FILE "blah.sav". INCLUDE "C:\Temp\save file.sps". Resulting in: Data written to C:\Temp\Management_Index – ABC .xls. 4 variables and 4 cases written to range: SPSS. Variable: DAY Type: Number Width: 8 Dec: 2 Variable: MONTH Type: Number Width: 8 Dec: 2 Variable: YEAR Type: Number Width: 8 Dec: 2 Variable: ABC Type: Number Width: 8 Dec: 2
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" |
|
Makes me shudder.
Jon Peck (no "h") aka Kim Senior Software Engineer, IBM [hidden email] new phone: 720-342-5621 From: David Marso <[hidden email]> To: [hidden email] Date: 03/08/2012 04:46 PM Subject: Re: [SPSSX-L] Using a variable or cell in a Save file name Sent by: "SPSSX(r) Discussion" <[hidden email]> I dislike this approach very much too ;-) OTOH: I'm the one who first introduced it about 20 years ago! So, while we are here, for old times: I'll see JoNoH's Python and Your OMS and *RAISE* you a FLIP!!!! N.B. Could use INSERT rather than INCLUDE and diddle the DATA SET biz rather than SAVE if that floats your boat ;-)))) ---- DATA LIST FREE/day month year ABC. BEGIN DATA 1 2 2002 1 14 1 2003 0 5 2 2004 1 9 2 2007 1 END DATA. SAVE OUTFILE "blah.sav". SELECT IF $CASENUM=1. FLIP. DO IF ($CASENUM=4). write outfile = "C:\Temp\save file.sps" / "SAVE TRANSLATE OUTFILE='C:\Temp\Management_Index – ", CASE_LBL , ".xls'" / " /TYPE=XLS /VERSION=2/MAP/REPLACE/FIELDNAMES.". END IF. EXE. GET FILE "blah.sav". INCLUDE "C:\Temp\save file.sps". Resulting in: Data written to C:\Temp\Management_Index – ABC .xls. 4 variables and 4 cases written to range: SPSS. Variable: DAY Type: Number Width: 8 Dec: 2 Variable: MONTH Type: Number Width: 8 Dec: 2 Variable: YEAR Type: Number Width: 8 Dec: 2 Variable: ABC Type: Number Width: 8 Dec: 2 Bruce Weaver wrote > > I know Jon dislikes this approach very much, but here's another way to do > it that does *not* require Python. ;-) > > * Read in the sample data. > DATA LIST LIST /day month year ABC. > BEGIN DATA > 1 2 2002 1 > 14 1 2003 0 > 5 2 2004 1 > 9 2 2007 1 > END DATA. > dataset name f1. > > DATASET DECLARE f2. > OMS > /SELECT TABLES > /IF COMMANDS=['File Information'] SUBTYPES=['Variable Information'] > /DESTINATION FORMAT=SAV NUMBERED=tnum > OUTFILE='f2'. > > display dictionary. > OMSEND. > > dataset activate f2. > compute case = $casenum. > execute. /* A case where EXECUTE is needed! . > select if case EQ 4. /* Select the 4th variable. > execute. > > alter type Var1(amin). /* Var1 holds the variable name. > write outfile = "C:\Temp\save file.sps" / > "SAVE TRANSLATE OUTFILE='C:\Temp\Management_Index – ", Var1, ".xls'" / > " /TYPE=XLS" / > " /VERSION=2" / > " /MAP" / > " /REPLACE" / > " /FIELDNAMES." > . > execute. > > dataset activate f1. > INSERT FILE = "C:\Temp\save file.sps". > dataset close f2. > > > > Jon K Peck wrote >> >> This sort of thing requires the Python Essentials. If you have installed >> these, you can do it this way. >> >> begin program. >> import spss >> varname = spss.GetVariableName(3) >> spss.Submit(r"""SAVE TRANSLATE /OUTFILE="C:\Desktop\Management_Index – >> %s.xls" ...""" % varname) >> end program. >> >> Variable indexes count from 0 in Python. >> Replace the ... with whatever other SAVE TRANSLATE syntax is required. >> The >> %s will be replace by the name of the 4th variable. >> >> HTH, >> >> Jon Peck (no "h") aka Kim >> Senior Software Engineer, IBM >> peck@.ibm >> new phone: 720-342-5621 >> >> >> >> >> From: Keith Howey <KHowey@> >> To: SPSSX-L@.uga >> Date: 03/08/2012 10:03 AM >> Subject: [SPSSX-L] Using a variable or cell in a Save file name >> Sent by: "SPSSX(r) Discussion" <SPSSX-L@.uga> >> >> >> >> Is there a way to save a variable name in a Save file name. >> >> For instance, if I have: >> >> DATA LIST LIST /day month year ABC. >> BEGIN DATA >> 1 2 2002 1 >> 14 1 2003 0 >> 5 2 2004 1 >> 9 2 2007 1 >> END DATA. >> >> Can I create a Save Translate to Excel with “ABC” in its name because >> it’s >> V4. >> >> In the end I would like a file named 'C:\Desktop\Management_Index – >> ABC.xls’ and if I changed V4, the Excel file name would change. >> >> Thanks, >> >> Keith Howey >> Evaluation Associate >> Common Ground Community >> 505 8th Avenue, 12th Floor >> New York, NY 10018 >> (212) 389-9383 >> khowey@ >> >> >> >> >> Innovative Programs that Transform People, Buildings and Communities >> www.commonground.org >> >> Please consider the environment before printing this e-mail. >> > -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Using-a-variable-or-cell-in-a-Save-file-name-tp5548148p5549235.html Sent from the SPSSX Discussion mailing list archive at Nabble.com. ===================== 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 |
|
Administrator
|
In reply to this post by David Marso
Yes, I thought you were responsible for that, David. I didn't think of FLIP. In either case, one could tidy up afterwards by getting rid of the syntax file created via WRITE.
ERASE FILE = "C:\Temp\save file.sps"
--
Bruce Weaver bweaver@lakeheadu.ca http://sites.google.com/a/lakeheadu.ca/bweaver/ "When all else fails, RTFM." PLEASE NOTE THE FOLLOWING: 1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above. 2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/). |
|
Administrator
|
In reply to this post by Jon K Peck
Well, some of the uglier Python code floating (typically uncommented) about makes me want to extract my eyeballs with a grapefruit spoon ;-)
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" |
|
As in Slumdog Millionaire, you mean?
-----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of David Marso Sent: 09 March 2012 03:00 To: [hidden email] Subject: Re: Using a variable or cell in a Save file name Well, some of the uglier Python code floating (typically uncommented) about makes me want to extract my eyeballs with a grapefruit spoon ;-) Jon K Peck wrote > > Makes me shudder. > > Jon Peck (no "h") aka Kim > Senior Software Engineer, IBM > peck@.ibm > new phone: 720-342-5621 > > > > > From: David Marso <david.marso@> > To: SPSSX-L@.uga > Date: 03/08/2012 04:46 PM > Subject: Re: [SPSSX-L] Using a variable or cell in a Save file name > Sent by: "SPSSX(r) Discussion" <SPSSX-L@.uga> > > > > I dislike this approach very much too ;-) > OTOH: I'm the one who first introduced it about 20 years ago! > So, while we are here, for old times: > I'll see JoNoH's Python and Your OMS and *RAISE* you a FLIP!!!! > N.B. Could use INSERT rather than INCLUDE and diddle the DATA SET biz > rather than SAVE if that floats your boat ;-)))) > ---- > DATA LIST FREE/day month year ABC. > BEGIN DATA > 1 2 2002 1 14 1 2003 0 5 2 2004 1 9 2 2007 1 END DATA. > SAVE OUTFILE "blah.sav". > SELECT IF $CASENUM=1. > FLIP. > DO IF ($CASENUM=4). > write outfile = "C:\Temp\save file.sps" / "SAVE TRANSLATE > OUTFILE='C:\Temp\Management_Index – ", CASE_LBL , ".xls'" > / > " /TYPE=XLS /VERSION=2/MAP/REPLACE/FIELDNAMES.". > END IF. > EXE. > GET FILE "blah.sav". > INCLUDE "C:\Temp\save file.sps". > > Resulting in: > > Data written to C:\Temp\Management_Index – ABC .xls. > 4 variables and 4 cases written to range: SPSS. > Variable: DAY Type: Number Width: 8 Dec: 2 > Variable: MONTH Type: Number Width: 8 Dec: 2 > Variable: YEAR Type: Number Width: 8 Dec: 2 > Variable: ABC Type: Number Width: 8 Dec: 2 > > Bruce Weaver wrote >> >> I know Jon dislikes this approach very much, but here's another way >> to > do >> it that does *not* require Python. ;-) >> >> * Read in the sample data. >> DATA LIST LIST /day month year ABC. >> BEGIN DATA >> 1 2 2002 1 >> 14 1 2003 0 >> 5 2 2004 1 >> 9 2 2007 1 >> END DATA. >> dataset name f1. >> >> DATASET DECLARE f2. >> OMS >> /SELECT TABLES >> /IF COMMANDS=['File Information'] SUBTYPES=['Variable Information'] >> /DESTINATION FORMAT=SAV NUMBERED=tnum >> OUTFILE='f2'. >> >> display dictionary. >> OMSEND. >> >> dataset activate f2. >> compute case = $casenum. >> execute. /* A case where EXECUTE is needed! . >> select if case EQ 4. /* Select the 4th variable. >> execute. >> >> alter type Var1(amin). /* Var1 holds the variable name. >> write outfile = "C:\Temp\save file.sps" / >> "SAVE TRANSLATE OUTFILE='C:\Temp\Management_Index – ", Var1, ".xls'" / >> " /TYPE=XLS" / >> " /VERSION=2" / >> " /MAP" / >> " /REPLACE" / >> " /FIELDNAMES." >> . >> execute. >> >> dataset activate f1. >> INSERT FILE = "C:\Temp\save file.sps". >> dataset close f2. >> >> >> >> Jon K Peck wrote >>> >>> This sort of thing requires the Python Essentials. If you have > installed >>> these, you can do it this way. >>> >>> begin program. >>> import spss >>> varname = spss.GetVariableName(3) >>> spss.Submit(r"""SAVE TRANSLATE /OUTFILE="C:\Desktop\Management_Index >>> – %s.xls" ...""" % varname) end program. >>> >>> Variable indexes count from 0 in Python. >>> Replace the ... with whatever other SAVE TRANSLATE syntax is required. >>> The >>> %s will be replace by the name of the 4th variable. >>> >>> HTH, >>> >>> Jon Peck (no "h") aka Kim >>> Senior Software Engineer, IBM >>> peck@.ibm >>> new phone: 720-342-5621 >>> >>> >>> >>> >>> From: Keith Howey <KHowey@> >>> To: SPSSX-L@.uga >>> Date: 03/08/2012 10:03 AM >>> Subject: [SPSSX-L] Using a variable or cell in a Save file name >>> Sent by: "SPSSX(r) Discussion" <SPSSX-L@.uga> >>> >>> >>> >>> Is there a way to save a variable name in a Save file name. >>> >>> For instance, if I have: >>> >>> DATA LIST LIST /day month year ABC. >>> BEGIN DATA >>> 1 2 2002 1 >>> 14 1 2003 0 >>> 5 2 2004 1 >>> 9 2 2007 1 >>> END DATA. >>> >>> Can I create a Save Translate to Excel with “ABC” in its name >>> because it’s V4. >>> >>> In the end I would like a file named 'C:\Desktop\Management_Index – >>> ABC.xls’ and if I changed V4, the Excel file name would change. >>> >>> Thanks, >>> >>> Keith Howey >>> Evaluation Associate >>> Common Ground Community >>> 505 8th Avenue, 12th Floor >>> New York, NY 10018 >>> (212) 389-9383 >>> khowey@ >>> >>> >>> >>> >>> Innovative Programs that Transform People, Buildings and Communities >>> www.commonground.org >>> >>> Please consider the environment before printing this e-mail. >>> >> > > > -- > View this message in context: > http://spssx-discussion.1045642.n5.nabble.com/Using-a-variable-or-cell > -in-a-Save-file-name-tp5548148p5549235.html > > Sent from the SPSSX Discussion mailing list archive at Nabble.com. > > ===================== > To manage your subscription to SPSSX-L, send a message to > LISTSERV@.UGA (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 > -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Using-a-variable-or-cell-in-a-Save-file-name-tp5548148p5549450.html Sent from the SPSSX Discussion mailing list archive at Nabble.com. ===================== 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 |
|
Administrator
|
In reply to this post by Bruce Weaver
People seem to forget that there is also BASIC scripting which has been deprecated due to a strange emphasis on python and avid propaganda emanating from the dominant pythonista camp.
Before python even existed as a language the same capabilities existed in the SAX scripting (since SPSS 7.5 or was it 7.0 -who f'n cares-) (or you could do it in VB, VBA or whatever). At any rate, I wouldn't be surprised if the following still works in SPSS 20 (unless backward compatibility has become completely irrelevant). You could of course run this from syntax using the SCRIPT command and generalize it using objspssapp.ScriptParameter (0) and pass it a value . I believe one can also use inline BASIC as part of BEGIN PROGRAM end PROGRAM block but I have not seen this because Python is so f'ing cool ;-))) -- Sub Main Dim Varnames As Variant Dim syntax As String Varnames= objSpssApp.Documents.GetDataDoc(0).GetVariables (False) syntax="SAVE TRANSLATE OUTFILE='C:\Temp\Management_Index – " & _ Varnames(3) & ".xls'" & "/Type=XLS/VERSION=2 /MAP/Replace/FIELDNAMES." objSpssApp.ExecuteCommands (syntax,False) End Sub ---
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" |
|
Basic scripting is still available - Windows
only - but its capabilities are far more limited than Python. You
cannot run it in BEGIN/END PROGRAM for fundamental architectural reasons.
Basic scripting (no longer called SaxBasic) runs in the Statistics frontend process and uses Windows COM-based apis, so it is better at working with the Viewer and UI objects than with the data and backend functionality. Most old SaxBasic scripts will work unchanged in newer Statistics versions, but there are some small changes required for Basic autoscripts and in a few dark corners. The .NET plugin allow you to use VB.NET and C#, among other languages but operates only to drive an invisible SPSS Processor. Python programmability runs with the backend process (the SPSS Processor) and Python scripting with the frontend process (no COM), so it works well with both. R programmability works only with the backend process. Extension commands can be written in Python or R but not Basic. To each his own. Jon Peck (no "h") aka Kim Senior Software Engineer, IBM [hidden email] new phone: 720-342-5621 From: David Marso <[hidden email]> To: [hidden email] Date: 03/09/2012 07:14 AM Subject: Re: [SPSSX-L] Using a variable or cell in a Save file name Sent by: "SPSSX(r) Discussion" <[hidden email]> People seem to forget that there is also BASIC scripting which has been deprecated due to a strange emphasis on python and avid propaganda emanating from the dominant pythonista camp. Before python even existed as a language the same capabilities existed in the SAX scripting (since SPSS 7.5 or was it 7.0 -who f'n cares-) (or you could do it in VB, VBA or whatever). At any rate, I wouldn't be surprised if the following still works in SPSS 20 (unless backward compatibility has become completely irrelevant). You could of course run this from syntax using the SCRIPT command and generalize it using objspssapp.ScriptParameter (0) and pass it a value . I believe one can also use inline BASIC as part of BEGIN PROGRAM end PROGRAM block but I have not seen this because Python is so f'ing cool ;-))) -- Sub Main Dim Varnames As Variant Dim syntax As String Varnames= objSpssApp.Documents.GetDataDoc(0).GetVariables (False) syntax="SAVE TRANSLATE OUTFILE='C:\Temp\Management_Index – " & _ Varnames(3) & ".xls'" & "/Type=XLS/VERSION=2 /MAP/Replace/FIELDNAMES." objSpssApp.ExecuteCommands (syntax,False) End Sub --- Bruce Weaver wrote > > Yes, I thought you were responsible for that, David. I didn't think of > FLIP. In either case, one could tidy up afterwards by getting rid of the > syntax file created via WRITE. > > ERASE FILE = "C:\Temp\save file.sps" > > > > David Marso wrote >> >> I dislike this approach very much too ;-) >> OTOH: I'm the one who first introduced it about 20 years ago! >> So, while we are here, for old times: >> I'll see JoNoH's Python and Your OMS and *RAISE* you a FLIP!!!! >> N.B. Could use INSERT rather than INCLUDE and diddle the DATA SET biz >> rather than SAVE if that floats your boat ;-)))) >> ---- >> DATA LIST FREE/day month year ABC. >> BEGIN DATA >> 1 2 2002 1 14 1 2003 0 5 2 2004 1 9 2 2007 1 >> END DATA. >> SAVE OUTFILE "blah.sav". >> SELECT IF $CASENUM=1. >> FLIP. >> DO IF ($CASENUM=4). >> write outfile = "C:\Temp\save file.sps" / >> "SAVE TRANSLATE OUTFILE='C:\Temp\Management_Index – ", CASE_LBL , ".xls'" >> / >> " /TYPE=XLS /VERSION=2/MAP/REPLACE/FIELDNAMES.". >> END IF. >> EXE. >> GET FILE "blah.sav". >> INCLUDE "C:\Temp\save file.sps". >> >> Resulting in: >> >> Data written to C:\Temp\Management_Index – ABC .xls. >> 4 variables and 4 cases written to range: SPSS. >> Variable: DAY Type: Number Width: 8 Dec: 2 >> Variable: MONTH Type: Number Width: 8 Dec: 2 >> Variable: YEAR Type: Number Width: 8 Dec: 2 >> Variable: ABC Type: Number Width: 8 Dec: 2 >> >> Bruce Weaver wrote >>> >>> I know Jon dislikes this approach very much, but here's another way to >>> do it that does *not* require Python. ;-) >>> >>> * Read in the sample data. >>> DATA LIST LIST /day month year ABC. >>> BEGIN DATA >>> 1 2 2002 1 >>> 14 1 2003 0 >>> 5 2 2004 1 >>> 9 2 2007 1 >>> END DATA. >>> dataset name f1. >>> >>> DATASET DECLARE f2. >>> OMS >>> /SELECT TABLES >>> /IF COMMANDS=['File Information'] SUBTYPES=['Variable Information'] >>> /DESTINATION FORMAT=SAV NUMBERED=tnum >>> OUTFILE='f2'. >>> >>> display dictionary. >>> OMSEND. >>> >>> dataset activate f2. >>> compute case = $casenum. >>> execute. /* A case where EXECUTE is needed! . >>> select if case EQ 4. /* Select the 4th variable. >>> execute. >>> >>> alter type Var1(amin). /* Var1 holds the variable name. >>> write outfile = "C:\Temp\save file.sps" / >>> "SAVE TRANSLATE OUTFILE='C:\Temp\Management_Index – ", Var1, ".xls'" / >>> " /TYPE=XLS" / >>> " /VERSION=2" / >>> " /MAP" / >>> " /REPLACE" / >>> " /FIELDNAMES." >>> . >>> execute. >>> >>> dataset activate f1. >>> INSERT FILE = "C:\Temp\save file.sps". >>> dataset close f2. >>> >>> >>> >>> Jon K Peck wrote >>>> >>>> This sort of thing requires the Python Essentials. If you have >>>> installed >>>> these, you can do it this way. >>>> >>>> begin program. >>>> import spss >>>> varname = spss.GetVariableName(3) >>>> spss.Submit(r"""SAVE TRANSLATE /OUTFILE="C:\Desktop\Management_Index – >>>> %s.xls" ...""" % varname) >>>> end program. >>>> >>>> Variable indexes count from 0 in Python. >>>> Replace the ... with whatever other SAVE TRANSLATE syntax is required. >>>> The >>>> %s will be replace by the name of the 4th variable. >>>> >>>> HTH, >>>> >>>> Jon Peck (no "h") aka Kim >>>> Senior Software Engineer, IBM >>>> peck@.ibm >>>> new phone: 720-342-5621 >>>> >>>> >>>> >>>> >>>> From: Keith Howey <KHowey@> >>>> To: SPSSX-L@.uga >>>> Date: 03/08/2012 10:03 AM >>>> Subject: [SPSSX-L] Using a variable or cell in a Save file name >>>> Sent by: "SPSSX(r) Discussion" <SPSSX-L@.uga> >>>> >>>> >>>> >>>> Is there a way to save a variable name in a Save file name. >>>> >>>> For instance, if I have: >>>> >>>> DATA LIST LIST /day month year ABC. >>>> BEGIN DATA >>>> 1 2 2002 1 >>>> 14 1 2003 0 >>>> 5 2 2004 1 >>>> 9 2 2007 1 >>>> END DATA. >>>> >>>> Can I create a Save Translate to Excel with “ABC” in its name because >>>> it’s >>>> V4. >>>> >>>> In the end I would like a file named 'C:\Desktop\Management_Index – >>>> ABC.xls’ and if I changed V4, the Excel file name would change. >>>> >>>> Thanks, >>>> >>>> Keith Howey >>>> Evaluation Associate >>>> Common Ground Community >>>> 505 8th Avenue, 12th Floor >>>> New York, NY 10018 >>>> (212) 389-9383 >>>> khowey@ >>>> >>>> >>>> >>>> >>>> Innovative Programs that Transform People, Buildings and Communities >>>> www.commonground.org >>>> >>>> Please consider the environment before printing this e-mail. >>>> >>> >> > -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Using-a-variable-or-cell-in-a-Save-file-name-tp5548148p5550680.html Sent from the SPSSX Discussion mailing list archive at Nabble.com. ===================== 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 |
