Export SPSS text output

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

Export SPSS text output

Winson Yeung
Dear all,

I encounter a problem when trying to export a text output to text file and read in to SPSS with script and syntax, does anyone know how to solve it?

Thanks & Regards,
Winson

********************** PROBLEM BELOW ********************** .
There are two files in the following...
1- export.sps
2-ExportOutputWithGivenFilenameAndPath.sbs

Problem:
The export.sps is using script file (ExportOutputWithGivenFilenameAndPath.sbs) which is used to export the text output to a text file.
define !thepath() "I:\clean-macro\" !enddefine.
SCRIPT "I:\clean-macro\ExportOutputWithGivenFilenameAndPath.sbs"
 (!thepath+"output").

Then the content text output will then be shown in SPSS data by running...
DATA LIST
 FILE=!thepath+"output.txt"    records=1
 /1
 line     1-132 (a)
.
*</Output>.

However, error would be found if we run the whole file ...
>Error # 31 in column 8.  Text: I:\clean-macro\output.txt
>File not found.
>This command not executed.

We suspect the program running the script and the following syntax at the same time.  That is there is not enough time to save output.txt file (by scrpit).
If we run the script first and run the rest of syntax after a while, there will be no problem.

Would that be any command to force the script to run first so that the file can be used for the following syntax?


export.sps
************************************************************************************************************.
*<OUTFILE txt="Full" B="Short" xls="sorted">
----------------------------------.
define !thepath() "I:\clean-macro\" !enddefine.
SCRIPT "I:\clean-macro\ExportOutputWithGivenFilenameAndPath.sbs"
 (!thepath+"output").

*<Output note>.
DATA LIST
 FILE=!thepath+"output.txt"    records=1
 /1
 line     1-132 (a)
.
*</Output>.
EXECUTE.

************************************************************************************************************.

ExportOutputWithGivenFilenameAndPath.sbs:
************************************************************************************************************.
'Begin Description
'This script saves the current Designated Output window, export it as txt file.
'End Description

Option Explicit
Sub Main()

Dim strFile As String
'First check to see if the script was invoked from syntax,
'and a filename is provided as a script parameter.
On Error Resume Next
strFile = objSpssApp.ScriptParameter(0)

Dim objOutputDoc As ISpssOutputDoc
Set objOutputDoc= objSpssApp.GetDesignatedOutputDoc

If strFile = Empty Then
 objOutputDoc.ExportDocument (1,"c:\temp\output",1,0)
Else
 objOutputDoc.ExportDocument (1,strFile,1,0)
End If

Set objOutputDoc=Nothing
End Sub
************************************************************************************************************.
Reply | Threaded
Open this post in threaded view
|

Re: Export SPSS text output

Antro
Hi Winson,

You could always put the DATA LIST commands in to the script as well, or call the rest of the syntax file (assuming you do stuff after you read the data in) by using the ExecuteInsert command in the script file and pointing to a secnd syntax file.

HTH,
Antro.

Winson Yeung wrote
Dear all,

I encounter a problem when trying to export a text output to text file and read in to SPSS with script and syntax, does anyone know how to solve it?

Thanks & Regards,
Winson

********************** PROBLEM BELOW ********************** .
There are two files in the following...
1- export.sps
2-ExportOutputWithGivenFilenameAndPath.sbs

Problem:
The export.sps is using script file (ExportOutputWithGivenFilenameAndPath.sbs) which is used to export the text output to a text file.
define !thepath() "I:\clean-macro\" !enddefine.
SCRIPT "I:\clean-macro\ExportOutputWithGivenFilenameAndPath.sbs"
 (!thepath+"output").

Then the content text output will then be shown in SPSS data by running...
DATA LIST
 FILE=!thepath+"output.txt"    records=1
 /1
 line     1-132 (a)
.
*</Output>.

However, error would be found if we run the whole file ...
>Error # 31 in column 8.  Text: I:\clean-macro\output.txt
>File not found.
>This command not executed.

We suspect the program running the script and the following syntax at the same time.  That is there is not enough time to save output.txt file (by scrpit).
If we run the script first and run the rest of syntax after a while, there will be no problem.

Would that be any command to force the script to run first so that the file can be used for the following syntax?


export.sps
************************************************************************************************************.
*<OUTFILE txt="Full" B="Short" xls="sorted">
----------------------------------.
define !thepath() "I:\clean-macro\" !enddefine.
SCRIPT "I:\clean-macro\ExportOutputWithGivenFilenameAndPath.sbs"
 (!thepath+"output").

*<Output note>.
DATA LIST
 FILE=!thepath+"output.txt"    records=1
 /1
 line     1-132 (a)
.
*</Output>.
EXECUTE.

************************************************************************************************************.

ExportOutputWithGivenFilenameAndPath.sbs:
************************************************************************************************************.
'Begin Description
'This script saves the current Designated Output window, export it as txt file.
'End Description

Option Explicit
Sub Main()

Dim strFile As String
'First check to see if the script was invoked from syntax,
'and a filename is provided as a script parameter.
On Error Resume Next
strFile = objSpssApp.ScriptParameter(0)

Dim objOutputDoc As ISpssOutputDoc
Set objOutputDoc= objSpssApp.GetDesignatedOutputDoc

If strFile = Empty Then
 objOutputDoc.ExportDocument (1,"c:\temp\output",1,0)
Else
 objOutputDoc.ExportDocument (1,strFile,1,0)
End If

Set objOutputDoc=Nothing
End Sub
************************************************************************************************************.
Reply | Threaded
Open this post in threaded view
|

Re: Export SPSS text output

Winson Yeung
Thanks Antro,

Do you mean our guess is corrected? That is the program running the script
and the following syntax at the same time, and there is not enough time to
save output.txt file (by scrpit). Apart from running all the stuffs in script,
would that be any command to force the script to run first so that the
file can be used for the following syntax?

Thanks & Regards,
Winson


-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]]On Behalf Of Antro
Sent: Thursday, August 31, 2006 6:44 PM
To: [hidden email]
Subject: Re: Export SPSS text output


Hi Winson,

You could always put the DATA LIST commands in to the script as well, or
call the rest of the syntax file (assuming you do stuff after you read the
data in) by using the ExecuteInsert command in the script file and pointing
to a secnd syntax file.

HTH,
Antro.


Winson Yeung wrote:

>
> Dear all,
>
> I encounter a problem when trying to export a text output to text file and
> read in to SPSS with script and syntax, does anyone know how to solve it?
>
> Thanks & Regards,
> Winson
>
> ********************** PROBLEM BELOW ********************** .
> There are two files in the following...
> 1- export.sps
> 2-ExportOutputWithGivenFilenameAndPath.sbs
>
> Problem:
> The export.sps is using script file
> (ExportOutputWithGivenFilenameAndPath.sbs) which is used to export the
> text output to a text file.
> define !thepath() "I:\clean-macro\" !enddefine.
> SCRIPT "I:\clean-macro\ExportOutputWithGivenFilenameAndPath.sbs"
>  (!thepath+"output").
>
> Then the content text output will then be shown in SPSS data by running...
> DATA LIST
>  FILE=!thepath+"output.txt"    records=1
>  /1
>  line     1-132 (a)
> .
> *</Output>.
>
> However, error would be found if we run the whole file ...
>>Error # 31 in column 8.  Text: I:\clean-macro\output.txt
>>File not found.
>>This command not executed.
>
> We suspect the program running the script and the following syntax at the
> same time.  That is there is not enough time to save output.txt file (by
> scrpit).
> If we run the script first and run the rest of syntax after a while, there
> will be no problem.
>
> Would that be any command to force the script to run first so that the
> file can be used for the following syntax?
>
>
> export.sps
> ************************************************************************************************************.
> *<OUTFILE txt="Full" B="Short" xls="sorted">
> ----------------------------------.
> define !thepath() "I:\clean-macro\" !enddefine.
> SCRIPT "I:\clean-macro\ExportOutputWithGivenFilenameAndPath.sbs"
>  (!thepath+"output").
>
> *<Output note>.
> DATA LIST
>  FILE=!thepath+"output.txt"    records=1
>  /1
>  line     1-132 (a)
> .
> *</Output>.
> EXECUTE.
>
> ************************************************************************************************************.
>
> ExportOutputWithGivenFilenameAndPath.sbs:
> ************************************************************************************************************.
> 'Begin Description
> 'This script saves the current Designated Output window, export it as txt
> file.
> 'End Description
>
> Option Explicit
> Sub Main()
>
> Dim strFile As String
> 'First check to see if the script was invoked from syntax,
> 'and a filename is provided as a script parameter.
> On Error Resume Next
> strFile = objSpssApp.ScriptParameter(0)
>
> Dim objOutputDoc As ISpssOutputDoc
> Set objOutputDoc= objSpssApp.GetDesignatedOutputDoc
>
> If strFile = Empty Then
>  objOutputDoc.ExportDocument (1,"c:\temp\output",1,0)
> Else
>  objOutputDoc.ExportDocument (1,strFile,1,0)
> End If
>
> Set objOutputDoc=Nothing
> End Sub
> ************************************************************************************************************.
>
>

--
View this message in context: http://www.nabble.com/Export-SPSS-text-output-tf2194424.html#a6076974
Sent from the SPSSX Discussion forum at Nabble.com.
Reply | Threaded
Open this post in threaded view
|

Re: Export SPSS text output

Antro
It seems logical, especially when you say that running the script first and then the syntax, works.

There is no way of pausing the syntax until the script has finished in syntax (though there are methods in scripting that wait until a sblock of syntax has run).

Simply have the two syntax files, with the script line the last command in the first one, and then the rest of your syntax in the second. Call the second syntax file either hardcoded in the script, or by passing it as a parameter to the script in the first syntax file (this maybe easier if people change this second file often and don't want to see the VB interface).

Antro.


Winson Yeung wrote
Thanks Antro,

Do you mean our guess is corrected? That is the program running the script
and the following syntax at the same time, and there is not enough time to
save output.txt file (by scrpit). Apart from running all the stuffs in script,
would that be any command to force the script to run first so that the
file can be used for the following syntax?

Thanks & Regards,
Winson