file writename

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

file writename

Jodene Fine
Dear SPSS gang,



I have a script which calls syntax. At the end of the syntax, I want to
output a text file by the name of the current working file, but with a
different extension (.1D).  I have tried this (pseudocode):



1. Initiate script

2. Interactive input of file to process

3. Parse path and filename and extension into variables (say strName for the
filename)

4. Make a .SAV file using strName

5. Call syntax, which performs transformations

6. Syntax writes out a temporary .1D file (temp.1D)

7. Script uses Name temp.1D as strFilename & ".1D"



It appears that the order of control of this code prevents the Name command
from executing in the proper order, I think that the Name command is
executed rather earlier than the syntax is being executed. As noted above, I
can't pass the file name from the script to the syntax, but I have a .SAV
file with the name I want.



Is there a way to strip the name of the current data file using syntax to
name the .1D as I write it out instead of using a temp.1D file? Or am I
overthinking as usual? Probably an embarrassingly easy solution, no? Oh,
BTW, I'm working in (sigh) v15. No Python.



On my knees,



Jodene









____________________________________

Jodene Goldenring Fine, Ph.D.

MSU Center for Neurodevelopmental Study

Departments of Psychology and Psychiatry

321 West Fee Hall

East Lansing, MI 48854



(517) 353-5035 (517) 432-2662 fax

[hidden email]   www.psychology.msu.edu/CNS



"Be a nice person and see if it works."

Chinese Fortune Cookie, Berkeley, CA, circa 1974



_________________________________________

Legal Notice
Electronic Mail is not secure, may not be read every day, and should not be
used for urgent or sensitive issues. The material in this transmission may
contain confidential information intended for the addressee. If you are not
the addressee, any disclosure or use of this information by you is strictly
prohibited. If you have received this transmission in error, please delete
it and destroy all copies

=====================
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
Reply | Threaded
Open this post in threaded view
|

Re: file writename

Richard Ristow
This has hung unanswered for most of a day, so in
default of a true Script person,
At 04:54 PM 5/13/2008, Jodene Fine wrote:

>I have a script which calls syntax. At the end
>of the syntax, I want to output a text file by
>the name of the current working file, but with a
>different extension (.1D).  I have tried this (pseudocode):
>
>1. Initiate script
>2. Interactive input of file to process
>3. Parse path and filename and extension into variables (say strName for the
>filename)
>4. Make a .SAV file using strName
>5. Call syntax, which performs transformations
>6. Syntax writes out a temporary .1D file (temp.1D)
>7. Script uses Name temp.1D as strFilename & ".1D"
>
>It appears that the order of control of this code prevents the Name command
>from executing in the proper order, I think that the Name command is
>executed rather earlier than the syntax is being executed.

I've never been a Scripter, but scripting the
SPSS processor with Sax Basic processor (and
using Visual Basic would probably be the same)
has always had synchronization issues. See
"Synchronizing Scripts and Syntax", pp.284 ff in
the second edition of Raynald Levesque's book(*).
Having the 'Name' command run before the SPSS
processor terminates, would be only too likely.

>As noted above, I can't pass the file name from
>the script to the syntax, but I have a .SAV file with the name I want.

I didn't realize that one was unsolved. So,
writing a macro definition to a file, and
INSERTing it in your syntax file (or vice versa) doesn't work?

>Is there a way to strip the name of the current
>data file using syntax to name the .1D as I
>write it out instead of using a temp.1D file?

That, unfortunately not. The SPSS processor
doesn't have programmatic access to the file names.

>Oh, BTW, I'm working in (sigh) v15. No Python.

But 15 has Python. Mis-typing the version number?

-With warmest regards,
  Richard
.....................
(*)Levesque, Raynald, "SPSS® Programming and Data
Management, 2nd Edition/A Guide for SPSS® and
SAS® Users". SPSS, Inc., Chicago, IL, 2005
(NOT later editions, which have much less about macros and scripting.)

=====================
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
Reply | Threaded
Open this post in threaded view
|

Re: file writename

Richard Ristow
In reply to this post by Jodene Fine
At 01:13 PM 5/14/2008, Jodene Fine wrote, off-list:

>>>I have a script which calls syntax. At the end of the syntax, [...]
>>>6. Syntax writes out a temporary .1D file (temp.1D)
>>>7. Script uses Name temp.1D as strFilename & ".1D"
>>>[But] I think that the Name command is executed rather earlier
>>>than the syntax is being executed.
>>
>>I'd written, Scripting the SPSS processor with Sax Basic processor
>>has always had synchronization issues.
>
>I took a look at Raynald's comments on this. [The known
>synchronization problem] is certainly what is happening.
>
>>>I can't pass the file name from the script to the syntax
>>
>>I didn't realize that one was unsolved. So, writing a macro
>>definition to a file, and INSERTing it in your syntax file (or vice
>>versa) doesn't work?
>
>It was solved by executing syntax from the script line-by-line to
>get the needed data and then name the file using Sax variables.

In other words, using Sax Basic as a macro processor. A perfectly
good technique, as far as it goes.

>So I succeeded in getting interactive selection of a text file,
>reading the file in, then naming the resulting .sav file.
>
>After which a syntax file is called to run a host of transformations
>and write out an ASCII file. The only way I see [to pass the name of
>the output text file] around this is to convert *all* of my syntax
>code into executable statements in Sax.

If you can execute SPSS statements from Sax line-by-line, and *IF*
"INSERT" or "INCLUDE" will work if executed this way, this might work
for you. The strategy is to run line-by-line only a short piece of
code with the filenames, and invoke the longer code after.

I'm using "ExecuteSPSSLine" as the call to execute an SPSS line; I
don't know the actual syntax. (I'm not a Sax player, just a bit of a
trombonist.)

' Define macro for file name

       CmdStr = "DEFINE !infile() '" & StrGetfile & "' !ENDDEFINE." & vbCr
       ExecuteSPSSLine(Cmdstr)

' Run the host of transformations, and output
' Relies on the program using macro "!infile" to name the
' input ".sav" and output "".1D" files.

       ExecuteSPSSLine("INSERT host_of_transformations.SPS")
..............
An alternative to writing the DEFINE for a macro, is to refer to the
files by file-handle names in the host_of_transformations program,
and execute the corresponding FILE HANDLE commands before the INSERT.

If INSERT or INCLUDE won't work when executed directly, it might work
to write the DEFINE (or FILE HANDLE) statements to a temporary file,
and invoke them from the main file.


' Define macro for file name

       CmdStr = "DEFINE !infile() '" & StrGetfile & "' !ENDDEFINE." & vbCr
       EraseDiskFile(Temp_Define.SPS)
       WriteDiskFile(Temp_Define.SPS,CmdStr)

' Run [main] syntax file

       Set objSyntaxDoc = objSpssApp.OpenSyntaxDoc ("testpassname.sps")

       objSyntaxDoc.Visible=True

       objSyntaxDoc.Run

       objSyntaxDoc.Close

       Set objSyntaxDoc = Nothing

WHERE the first line of "testpassname.sps" is

INSERT Temp_Define.SPS.

=====================
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