Running a Syntax File at the start of each SPSS session & Formatting/Wrap text in syntax editor

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

Running a Syntax File at the start of each SPSS session & Formatting/Wrap text in syntax editor

Ratna Wynn-2
Hi
 
I have two questions and would appreciate any guidance. I have SPSS 18 currently.
 
a) I have a file where I have a number of macros. I would like these to run at the start of each SPSS session. How do I get SPSS to automatically run them each time.
 
b) I sometime have to scroll right to see the text on my syntax editor. Is it possible to wrap text? Does anyone know how to do this.
 
Thanks,
 
Ratna
Reply | Threaded
Open this post in threaded view
|

Re: Running a Syntax File at the start of each SPSS session & Formatting/Wrap text in syntax editor

Jignesh Sutar
a) I've love to know how to do this also! What you could do otherwise is to run the file using the INSERT command but you would have to do this manually at each session....

b) Text editors can crop your lines to a specified number of characters. I know Komodo can do this but TextPad perhaps could also, which is free.


On 22 October 2010 15:35, Ratna Wynn <[hidden email]> wrote:
Hi
 
I have two questions and would appreciate any guidance. I have SPSS 18 currently.
 
a) I have a file where I have a number of macros. I would like these to run at the start of each SPSS session. How do I get SPSS to automatically run them each time.
 
b) I sometime have to scroll right to see the text on my syntax editor. Is it possible to wrap text? Does anyone know how to do this.
 
Thanks,
 
Ratna

Reply | Threaded
Open this post in threaded view
|

Re: Running a Syntax File at the start of each SPSS session & Formatting/Wrap text in syntax editor

Bruce Weaver
Administrator
From the Help files:

Startup Scripts

You can create a script that runs at the start of each session and a separate script that runs each time you switch servers. For Windows you can have versions of these scripts in both Python and Basic. For all other platforms the scripts can only be in Python.

• The startup script must be named StartClient_.py for Python or StartClient_.wwd for Basic.

• The script that runs when switching servers must be named StartServer_.py for Python or StartServer_.wwd for Basic.

• The scripts must be located in the scripts directory of the installation directory--located at the root of the installation directory for Windows and Linux, and under the Contents directory in the application bundle for Mac.

• On Windows, if the scripts directory contains both a Python and a Basic version of StartClient_ or StartServer_ then both versions are executed. The order of execution is the Python version followed by the Basic version.

•  If your system is configured to start up in distributed mode, then at the start of each session any StartClient_ scripts are run followed by any StartServer_ scripts. Note: The StartServer_ scripts also run each time you switch servers, but the StartClient_ scripts only run at the start of a session.

--- end of Help ---


The startup script can no doubt call the syntax file that defines your macros.


J Sutar wrote
a) I've love to know how to do this also! What you could do otherwise is to
run the file using the INSERT command but you would have to do this manually
at each session....

b) Text editors can crop your lines to a specified number of characters. I
know Komodo can do this but TextPad perhaps could also, which is free.


On 22 October 2010 15:35, Ratna Wynn <ratnawynn@gmail.com> wrote:

> Hi
>
> I have two questions and would appreciate any guidance.* *I have SPSS 18
> currently.
>
> a) I have a file where I have a number of macros. I would like these to run
> at the start of each SPSS session. How do I get SPSS to automatically run
> them each time.
>
> b) I sometime have to scroll right to see the text on my syntax editor. Is
> it possible to wrap text? Does anyone know how to do this.
>
> Thanks,
>
> Ratna
>
--
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/).
Reply | Threaded
Open this post in threaded view
|

Re: Running a Syntax File at the start of each SPSS session & Formatting/Wrap text in syntax editor

Jon K Peck
In reply to this post by Jignesh Sutar
You can run a syntax file at startup (or on switching servers in distributed mode), by creating a simple script file (Python or Basic) that just issues a run command.  The script file(s) need to have specific names and be in a specific directory.  See the topic Startup Scripts under Scripting in the main help for details.

Jon Peck
Senior Software Engineer, IBM
[hidden email]
312-651-3435




From:        J Sutar <[hidden email]>
To:        [hidden email]
Date:        10/22/2010 01:03 PM
Subject:        Re: [SPSSX-L] Running a Syntax File at the start of each SPSS              session &              Formatting/Wrap text in syntax editor
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




a) I've love to know how to do this also! What you could do otherwise is to run the file using the INSERT command but you would have to do this manually at each session....

b) Text editors can crop your lines to a specified number of characters. I know Komodo can do this but TextPad perhaps could also, which is free.


On 22 October 2010 15:35, Ratna Wynn <ratnawynn@...> wrote:
Hi
 
I have two questions and would appreciate any guidance. I have SPSS 18 currently.
 
a) I have a file where I have a number of macros. I would like these to run at the start of each SPSS session. How do I get SPSS to automatically run them each time.
 
b) I sometime have to scroll right to see the text on my syntax editor. Is it possible to wrap text? Does anyone know how to do this.
 
Thanks,
 
Ratna

Reply | Threaded
Open this post in threaded view
|

Re: Running a Syntax File at the start of each SPSS session & Formatting/Wrap text in syntax editor

Ratna Wynn-2
In reply to this post by Bruce Weaver
Thank you!
 
I did try and do this. In fact my script file looks like this.
Option Explicit
Sub Main
objSpssApp.ExecuteInclude ("C:\Documents and Settings\Ratna.wynn\Desktop\SPSS Training\All Macros.sps",False)

End Sub
And as you note in your email I did try and save this as StartClient_.wwd. I saved it in the script folder under SPSS 18.0. But when I open SPSS I think it tries to run the file but ends up giving me an error. See below.
ERROR : (16309) No error.

Error : Expecting a valid data type (eg. Integer).

I am not sure what I am doing wrong here. Any help would be great. The odd thing is when I run the script all by itself it works with no errors.
 
Thanks,
 
Ratna
On Fri, Oct 22, 2010 at 3:18 PM, Bruce Weaver <[hidden email]> wrote:
From the Help files:

Startup Scripts

You can create a script that runs at the start of each session and a
separate script that runs each time you switch servers. For Windows you can
have versions of these scripts in both Python and Basic. For all other
platforms the scripts can only be in Python.

• The startup script must be named StartClient_.py for Python or
StartClient_.wwd for Basic.

• The script that runs when switching servers must be named StartServer_.py
for Python or StartServer_.wwd for Basic.

• The scripts must be located in the scripts directory of the installation
directory--located at the root of the installation directory for Windows and
Linux, and under the Contents directory in the application bundle for Mac.

• On Windows, if the scripts directory contains both a Python and a Basic
version of StartClient_ or StartServer_ then both versions are executed. The
order of execution is the Python version followed by the Basic version.

•  If your system is configured to start up in distributed mode, then at the
start of each session any StartClient_ scripts are run followed by any
StartServer_ scripts. Note: The StartServer_ scripts also run each time you
switch servers, but the StartClient_ scripts only run at the start of a
session.

--- end of Help ---


The startup script can no doubt call the syntax file that defines your
macros.



J Sutar wrote:
>
> a) I've love to know how to do this also! What you could do otherwise is
> to
> run the file using the INSERT command but you would have to do this
> manually
> at each session....
>
> b) Text editors can crop your lines to a specified number of characters. I
> know Komodo can do this but TextPad perhaps could also, which is free.
>
>
> On 22 October 2010 15:35, Ratna Wynn <[hidden email]> wrote:
>
>> Hi
>>
>> I have two questions and would appreciate any guidance.* *I have SPSS 18
>> currently.
>>
>> a) I have a file where I have a number of macros. I would like these to
>> run
>> at the start of each SPSS session. How do I get SPSS to automatically run
>> them each time.
>>
>> b) I sometime have to scroll right to see the text on my syntax editor.
>> Is
>> it possible to wrap text? Does anyone know how to do this.
>>
>> Thanks,
>>
>> Ratna
>>
>
>


-----
--
Bruce Weaver
[hidden email]
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.

--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Running-a-Syntax-File-at-the-start-of-each-SPSS-session-Formatting-Wrap-text-in-syntax-editor-tp3232350p3232819.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

Reply | Threaded
Open this post in threaded view
|

Re: Running a Syntax File at the start of each SPSS session & Formatting/Wrap text in syntax editor

Jignesh Sutar
If I am trying to create a python version of StartClient_.py...what exactly do I write in the python file to call the .sps file with macro definitions?


 
On 22 October 2010 21:48, Ratna Wynn <[hidden email]> wrote:
Thank you!
 
I did try and do this. In fact my script file looks like this.
Option Explicit
Sub Main
objSpssApp.ExecuteInclude ("C:\Documents and Settings\Ratna.wynn\Desktop\SPSS Training\All Macros.sps",False)

End Sub
And as you note in your email I did try and save this as StartClient_.wwd. I saved it in the script folder under SPSS 18.0. But when I open SPSS I think it tries to run the file but ends up giving me an error. See below.
ERROR : (16309) No error.

Error : Expecting a valid data type (eg. Integer).

I am not sure what I am doing wrong here. Any help would be great. The odd thing is when I run the script all by itself it works with no errors.
 
Thanks,
 
Ratna
On Fri, Oct 22, 2010 at 3:18 PM, Bruce Weaver <[hidden email]> wrote:
From the Help files:

Startup Scripts

You can create a script that runs at the start of each session and a
separate script that runs each time you switch servers. For Windows you can
have versions of these scripts in both Python and Basic. For all other
platforms the scripts can only be in Python.

• The startup script must be named StartClient_.py for Python or
StartClient_.wwd for Basic.

• The script that runs when switching servers must be named StartServer_.py
for Python or StartServer_.wwd for Basic.

• The scripts must be located in the scripts directory of the installation
directory--located at the root of the installation directory for Windows and
Linux, and under the Contents directory in the application bundle for Mac.

• On Windows, if the scripts directory contains both a Python and a Basic
version of StartClient_ or StartServer_ then both versions are executed. The
order of execution is the Python version followed by the Basic version.

•  If your system is configured to start up in distributed mode, then at the
start of each session any StartClient_ scripts are run followed by any
StartServer_ scripts. Note: The StartServer_ scripts also run each time you
switch servers, but the StartClient_ scripts only run at the start of a
session.

--- end of Help ---


The startup script can no doubt call the syntax file that defines your
macros.



J Sutar wrote:
>
> a) I've love to know how to do this also! What you could do otherwise is
> to
> run the file using the INSERT command but you would have to do this
> manually
> at each session....
>
> b) Text editors can crop your lines to a specified number of characters. I
> know Komodo can do this but TextPad perhaps could also, which is free.
>
>
> On 22 October 2010 15:35, Ratna Wynn <[hidden email]> wrote:
>
>> Hi
>>
>> I have two questions and would appreciate any guidance.* *I have SPSS 18
>> currently.
>>
>> a) I have a file where I have a number of macros. I would like these to
>> run
>> at the start of each SPSS session. How do I get SPSS to automatically run
>> them each time.
>>
>> b) I sometime have to scroll right to see the text on my syntax editor.
>> Is
>> it possible to wrap text? Does anyone know how to do this.
>>
>> Thanks,
>>
>> Ratna
>>
>
>


-----
--
Bruce Weaver
[hidden email]
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.

--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Running-a-Syntax-File-at-the-start-of-each-SPSS-session-Formatting-Wrap-text-in-syntax-editor-tp3232350p3232819.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


Reply | Threaded
Open this post in threaded view
|

Re: Running a Syntax File at the start of each SPSS session & Formatting/Wrap text in syntax editor

Jon K Peck
You can write your startup script in either of two ways.  One is simply to have it execute an INSERT command.  For example,
import SpssClient
SpssClient.StartClient()
SpssClient.RunSyntax("""insert file="c:/data/startup.sps".""")
SpssClient.StopClient()

The other eliminates the need for a separate syntax file.  You can put the syntax to run in triple quotes in the RunSyntax call.  For example,
import SpssClient
SpssClient.StartClient()
SpssClient.RunSyntax("""first command.
second command.
...
""")
SpssClient.StopClient()

HTH,

Jon Peck
Senior Software Engineer, IBM
[hidden email]
312-651-3435




From:        J Sutar <[hidden email]>
To:        [hidden email]
Date:        10/23/2010 07:07 AM
Subject:        Re: [SPSSX-L] Running a Syntax File at the start of each SPSS              session &              Formatting/Wrap text in syntax editor
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




If I am trying to create a python version of StartClient_.py...what exactly do I write in the python file to call the .sps file with macro definitions?


 

On 22 October 2010 21:48, Ratna Wynn <ratnawynn@...> wrote:
Thank you!
 
I did try and do this. In fact my script file looks like this.
Option Explicit
Sub Main
objSpssApp.ExecuteInclude ("C:\Documents and Settings\Ratna.wynn\Desktop\SPSS Training\All Macros.sps",False)

End Sub

And as you note in your email I did try and save this as StartClient_.wwd. I saved it in the script folder under SPSS 18.0. But when I open SPSS I think it tries to run the file but ends up giving me an error. See below.
ERROR : (16309) No error.

Error : Expecting a valid data type (eg. Integer).

I am not sure what I am doing wrong here. Any help would be great. The odd thing is when I run the script all by itself it works with no errors.
 
Thanks,
 
Ratna
On Fri, Oct 22, 2010 at 3:18 PM, Bruce Weaver <bruce.weaver@...> wrote:
From the Help files:

Startup Scripts

You can create a script that runs at the start of each session and a
separate script that runs each time you switch servers. For Windows you can
have versions of these scripts in both Python and Basic. For all other
platforms the scripts can only be in Python.

• The startup script must be named StartClient_.py for Python or
StartClient_.wwd for Basic.

• The script that runs when switching servers must be named StartServer_.py
for Python or StartServer_.wwd for Basic.

• The scripts must be located in the scripts directory of the installation
directory--located at the root of the installation directory for Windows and
Linux, and under the Contents directory in the application bundle for Mac.

• On Windows, if the scripts directory contains both a Python and a Basic
version of StartClient_ or StartServer_ then both versions are executed. The
order of execution is the Python version followed by the Basic version.

•  If your system is configured to start up in distributed mode, then at the
start of each session any StartClient_ scripts are run followed by any
StartServer_ scripts. Note: The StartServer_ scripts also run each time you
switch servers, but the StartClient_ scripts only run at the start of a
session.

--- end of Help ---


The startup script can no doubt call the syntax file that defines your
macros.




J Sutar wrote:
>
> a) I've love to know how to do this also! What you could do otherwise is
> to
> run the file using the INSERT command but you would have to do this
> manually
> at each session....
>
> b) Text editors can crop your lines to a specified number of characters. I
> know Komodo can do this but TextPad perhaps could also, which is free.
>
>
> On 22 October 2010 15:35, Ratna Wynn <
ratnawynn@...> wrote:
>
>> Hi
>>
>> I have two questions and would appreciate any guidance.* *I have SPSS 18
>> currently.
>>
>> a) I have a file where I have a number of macros. I would like these to
>> run
>> at the start of each SPSS session. How do I get SPSS to automatically run
>> them each time.
>>
>> b) I sometime have to scroll right to see the text on my syntax editor.
>> Is
>> it possible to wrap text? Does anyone know how to do this.
>>
>> Thanks,
>>
>> Ratna
>>
>
>


-----
--
Bruce Weaver

bweaver@...
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.

--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/Running-a-Syntax-File-at-the-start-of-each-SPSS-session-Formatting-Wrap-text-in-syntax-editor-tp3232350p3232819.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
To manage your subscription to SPSSX-L, send a message to

LISTSERV@... (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: Running a Syntax File at the start of each SPSS session & Formatting/Wrap text in syntax editor

mils
Hi,

I've run the following python script:

import SpssClient
SpssClient.StartClient()
SpssClient.RunSyntax("""insert file="C:\Users\JoanC\Desktop\HBV\Wave 2\PRFs\import.sps".""")
SpssClient.StopClient()

To run an SPSS syntax which imports a CSV into SPSS and saves two different files.

For some reason, the python script creates both files but I can't open them. I had to open the Windows Task Manager to end the SPSS process.

Any idea why? I've attached the SPSS syntax.

Thanks in advance.

import.sps
mils
Reply | Threaded
Open this post in threaded view
|

Re: Running a Syntax File at the start of each SPSS session & Formatting/Wrap text in syntax editor

Jon K Peck
That is one monster GET DATA command!  I don't know what might have caused the problem, but I would recommend using the spss module rather than the SpssClient module for tasks like this.  Note also that in general you need an "r" in front of the filespec below in order to avoid misinterpretation of the backslash characters, which by default are interpreted as Python escapes.  In this particular case, none of the sequences is misinterpreted, but it will bite you sooner or later.

begin program.
import spss
spss.Submit(r"""insert file="C:\Users\JoanC\Desktop\HBV\Wave2\PRFs\import.sps".""")
end program.


Jon Peck (no "h") aka Kim
Senior Software Engineer, IBM
[hidden email]
phone: 720-342-5621




From:        mils <[hidden email]>
To:        [hidden email],
Date:        11/22/2013 10:55 AM
Subject:        Re: [SPSSX-L] Running a Syntax File at the start of each SPSS              session &              Formatting/Wrap text in syntax editor
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




Hi,

I've run the following python script:

import SpssClient
SpssClient.StartClient()
SpssClient.RunSyntax("""insert file="C:\Users\JoanC\Desktop\HBV\Wave
2\PRFs\import.sps".""")
SpssClient.StopClient()

To run an SPSS syntax which imports a CSV into SPSS and saves two different
files.

For some reason, the python script creates both files but I can't open them.
I had to open the Windows Task Manager to end the SPSS process.

Any idea why? I've attached the SPSS syntax.

Thanks in advance.

import.sps
<
http://spssx-discussion.1045642.n5.nabble.com/file/n5723251/import.sps>



-----
mils
--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/Running-a-Syntax-File-at-the-start-of-each-SPSS-session-Formatting-Wrap-text-in-syntax-editor-tp3232350p5723251.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


Reply | Threaded
Open this post in threaded view
|

Re: Running a Syntax File at the start of each SPSS session & Formatting/Wrap text in syntax editor

David Marso
Administrator
"That is one monster GET DATA command!  "
I had to look.
Comment:  I think your variable naming convention is STRANGE and would drive me NUTS in about 2 hours (some would argue that day is long past)!  
You are trying to pack VARIABLE LABELS into variable NAMES (questionable practice IMNSHO).  
Ideally you should place the key concept of the variable towards the beginning rather than a LONG subscale descriptor.  
OTOH:  That is your headache to deal with.  
Just because you CAN use 64 bytes in a variable name doesn't mean you should.  
If you do, place the differentiating aspects in front.  
You obviously design your syntax using point & click.  
No one would ever want to type any of those names..

Just my opinion
Jon K Peck wrote
That is one monster GET DATA command!  I don't know what might have caused
the problem, but I would recommend using the spss module rather than the
SpssClient module for tasks like this.  Note also that in general you need
an "r" in front of the filespec below in order to avoid misinterpretation
of the backslash characters, which by default are interpreted as Python
escapes.  In this particular case, none of the sequences is
misinterpreted, but it will bite you sooner or later.

begin program.
import spss
spss.Submit(r"""insert
file="C:\Users\JoanC\Desktop\HBV\Wave2\PRFs\import.sps".""")
end program.


Jon Peck (no "h") aka Kim
Senior Software Engineer, IBM
[hidden email]
phone: 720-342-5621




From:   mils <[hidden email]>
To:     [hidden email],
Date:   11/22/2013 10:55 AM
Subject:        Re: [SPSSX-L] Running a Syntax File at the start of each
SPSS              session &              Formatting/Wrap text in syntax
editor
Sent by:        "SPSSX(r) Discussion" <[hidden email]>



Hi,

I've run the following python script:

import SpssClient
SpssClient.StartClient()
SpssClient.RunSyntax("""insert file="C:\Users\JoanC\Desktop\HBV\Wave
2\PRFs\import.sps".""")
SpssClient.StopClient()

To run an SPSS syntax which imports a CSV into SPSS and saves two
different
files.

For some reason, the python script creates both files but I can't open
them.
I had to open the Windows Task Manager to end the SPSS process.

Any idea why? I've attached the SPSS syntax.

Thanks in advance.

import.sps
<http://spssx-discussion.1045642.n5.nabble.com/file/n5723251/import.sps>



-----
mils
--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/Running-a-Syntax-File-at-the-start-of-each-SPSS-session-Formatting-Wrap-text-in-syntax-editor-tp3232350p5723251.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
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?"
Reply | Threaded
Open this post in threaded view
|

Re: Running a Syntax File at the start of each SPSS session & Formatting/Wrap text in syntax editor

Ruben Geert van den Berg
If the number of macros is small, you use them a lot and they tend to take many variables, you could perhaps put the macro definitions and calls (with "wildcards") in custom dialogs.

Like that, they'll always be available when you start SPSS.

The availability of variable lists (selection with SHIFT key) in the custom dialog builder may perhaps circumvent writing out many variable names - which I think is one of the nastiest features of macros compared to Python (where you can use the super handy spssaux.VariableDict.expand() method).

It might also render the macros more accessible to those still suffering from SpssSyntaxPhobia - .spd files are very easily shared, installed and used.

Writing custom dialogs is the greatest fun I ever had - and finally it's not me anymore who's fetching coffee for my colleagues all day long.