Is there a way of getting SPSS to ‘see’ a constant?

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

Is there a way of getting SPSS to ‘see’ a constant?

Ron0z
If I have some code that reads data from several system files, does some
stuff, then saves the data to a new system file. Amongst the stuff I’m
getting it to do I have a compute statement – it’s the same statement in
each. It simply multiplies a variable by a particular value (ie. a
percentage value - rate). And what's the stuff I'm doing? A series of
computes and data manipulation - no statistics procedures.

If I'm required to alter the value I will then need to alter each compute
statement. Not really a problem other than the fact that mistakes could be
made, and of course, if I have lots then I have to alter each one.

When I used to play around with Pascal you could create a global variable to
be a constant, and it wouldn’t matter what part of the code it was accessed
the value would always  be the same, but in SPSS each time you read a new
file all the previous variables are dropped.

Here’s an example to give the flavour of what I’m on about. I’d like enter
Rate as shown. Of course, this does not work.  Each time spss comes across a
GET FILE the only data that’s available is what’s in the current data.  Is
there a way of getting SPSS to retain a variable and its value in memory for
the entire run, not just until the next GET FILE, or ADD FILES command?


COMPUTE Rate = 0.45.

GET FILE ‘data1.dat’.
SELECT IF (prop1 GT Rate).
..some stuff..
SAVE OUTFILE ‘outdata1.sys’.

GET FILE ‘data2.dat’.
SELECT IF (prop2 GT Rate).
..some other stuff..
SAVE OUTFILE ‘outdata2.sys’.

If you run this an error will be generated saying Rate is unknown, and of
course, you get it twice because there are two GET FILE commands there that
both use Rate.
>Error # 4285 in column 30.  Text: RATE
>Incorrect variable name: either the name is more than 64 characters, or it
is
>not defined by a previous command.




--
Sent from: http://spssx-discussion.1045642.n5.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: Is there a way of getting SPSS to ‘see’ a constant?

Bruce Weaver
Administrator
I don't have SPSS on this machine, so cannot test right now.  But I'd try
using a macro.

DEFINE !Rate () 0.45 !ENDDEFINE.

GET FILE ‘data1.dat’.
SELECT IF (prop1 GT !Rate).
..some stuff..
SAVE OUTFILE ‘outdata1.sys’.

GET FILE ‘data2.dat’.
SELECT IF (prop2 GT !Rate).
..some other stuff..
SAVE OUTFILE ‘outdata2.sys’.



Ron0z wrote

> If I have some code that reads data from several system files, does some
> stuff, then saves the data to a new system file. Amongst the stuff I’m
> getting it to do I have a compute statement – it’s the same statement in
> each. It simply multiplies a variable by a particular value (ie. a
> percentage value - rate). And what's the stuff I'm doing? A series of
> computes and data manipulation - no statistics procedures.
>
> If I'm required to alter the value I will then need to alter each compute
> statement. Not really a problem other than the fact that mistakes could be
> made, and of course, if I have lots then I have to alter each one.
>
> When I used to play around with Pascal you could create a global variable
> to
> be a constant, and it wouldn’t matter what part of the code it was
> accessed
> the value would always  be the same, but in SPSS each time you read a new
> file all the previous variables are dropped.
>
> Here’s an example to give the flavour of what I’m on about. I’d like enter
> Rate as shown. Of course, this does not work.  Each time spss comes across
> a
> GET FILE the only data that’s available is what’s in the current data.  Is
> there a way of getting SPSS to retain a variable and its value in memory
> for
> the entire run, not just until the next GET FILE, or ADD FILES command?
>
>
> COMPUTE Rate = 0.45.
>
> GET FILE ‘data1.dat’.
> SELECT IF (prop1 GT Rate).
> ..some stuff..
> SAVE OUTFILE ‘outdata1.sys’.
>
> GET FILE ‘data2.dat’.
> SELECT IF (prop2 GT Rate).
> ..some other stuff..
> SAVE OUTFILE ‘outdata2.sys’.
>
> If you run this an error will be generated saying Rate is unknown, and of
> course, you get it twice because there are two GET FILE commands there
> that
> both use Rate.
>>Error # 4285 in column 30.  Text: RATE
>>Incorrect variable name: either the name is more than 64 characters, or it
> is
>>not defined by a previous command.
>
>
>
>
> --
> Sent from: http://spssx-discussion.1045642.n5.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





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

--
Sent from: http://spssx-discussion.1045642.n5.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
--
Bruce Weaver
bweaver@lakeheadu.ca
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.
Reply | Threaded
Open this post in threaded view
|

Re: Is there a way of getting SPSS to ‘see’ a constant?

Jon Peck
To which I would add, if you want the definition(s) to be used in multiple jobs, put them in a separate file and use INSERT in each job.

If you want to set up a project environment that is automatically used each time you start a session, look at the STATS OPEN PROJECT extension command, which you can install from the Utilities or Extensions menu.
On Tue, Sep 19, 2017 at 7:58 PM Bruce Weaver <[hidden email]> wrote:
I don't have SPSS on this machine, so cannot test right now.  But I'd try

using a macro.



DEFINE !Rate () 0.45 !ENDDEFINE.



GET FILE ‘data1.dat’.

SELECT IF (prop1 GT !Rate).

..some stuff..

SAVE OUTFILE ‘outdata1.sys’.



GET FILE ‘data2.dat’.

SELECT IF (prop2 GT !Rate).

..some other stuff..

SAVE OUTFILE ‘outdata2.sys’.







Ron0z wrote

> If I have some code that reads data from several system files, does some

> stuff, then saves the data to a new system file. Amongst the stuff I’m

> getting it to do I have a compute statement – it’s the same statement in

> each. It simply multiplies a variable by a particular value (ie. a

> percentage value - rate). And what's the stuff I'm doing? A series of

> computes and data manipulation - no statistics procedures.

>

> If I'm required to alter the value I will then need to alter each compute

> statement. Not really a problem other than the fact that mistakes could be

> made, and of course, if I have lots then I have to alter each one.

>

> When I used to play around with Pascal you could create a global variable

> to

> be a constant, and it wouldn’t matter what part of the code it was

> accessed

> the value would always  be the same, but in SPSS each time you read a new

> file all the previous variables are dropped.

>

> Here’s an example to give the flavour of what I’m on about. I’d like enter

> Rate as shown. Of course, this does not work.  Each time spss comes across

> a

> GET FILE the only data that’s available is what’s in the current data.  Is

> there a way of getting SPSS to retain a variable and its value in memory

> for

> the entire run, not just until the next GET FILE, or ADD FILES command?

>

>

> COMPUTE Rate = 0.45.

>

> GET FILE ‘data1.dat’.

> SELECT IF (prop1 GT Rate).

> ..some stuff..

> SAVE OUTFILE ‘outdata1.sys’.

>

> GET FILE ‘data2.dat’.

> SELECT IF (prop2 GT Rate).

> ..some other stuff..

> SAVE OUTFILE ‘outdata2.sys’.

>

> If you run this an error will be generated saying Rate is unknown, and of

> course, you get it twice because there are two GET FILE commands there

> that

> both use Rate.

>>Error # 4285 in column 30.  Text: RATE

>>Incorrect variable name: either the name is more than 64 characters, or it

> is

>>not defined by a previous command.

>

>

>

>

> --

> Sent from: http://spssx-discussion.1045642.n5.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











-----

--

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.



--

Sent from: http://spssx-discussion.1045642.n5.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
Reply | Threaded
Open this post in threaded view
|

Re: Is there a way of getting SPSS to ‘see’ a constant?

Ron0z
In reply to this post by Bruce Weaver
MACRO is the prefect solution. That's exactly what I needed.  Many thanks.



--
Sent from: http://spssx-discussion.1045642.n5.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