Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Save computed variables?

3,021 views
Skip to first unread message

MG

unread,
Mar 7, 2011, 12:28:10 PM3/7/11
to
Hi

I am working in a extensive dataset - and I need to calculate new
variables based on the existing variables in the dataset.

Say if I have
Var1 Var2 Var3 Var4 Var5

And I need to calculate a new variable which is the sum of
var2+var3+var5
then I can choose transform->compute and compute the new variable

But if I want to check later whether that variable is correctly
calculated - spss have forgotten how it was calculated (or it is
overwritten because I have calculated several variables like this). So
how can I save such variable calculations? In Excel I would create a
formula which I can always turn back to and edit - but how is this
done in SPSS?

Thanks very much in advance for any help.


/MG

Bruce Weaver

unread,
Mar 7, 2011, 1:13:50 PM3/7/11
to

When you exit the menu for transform->compute, exit via the PASTE
button. This will generate syntax for your computation, which you can
save. For the computation to happen, you must then run the syntax.
See the RUN menu in the syntax window for various options (e.g., run
selected, run to end, run all).

For more info on why use of syntax is so essential, see:

http://www.spsstools.net/SampleSyntax.htm
http://www.spsstools.net/LearningSyntax.htm
http://www.spsstools.net/LearningSyntax.htm#KeyItems

Notice especially the 3rd link.

HTH.

--
Bruce Weaver
bwe...@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/Home
"When all else fails, RTFM."

Jon Peck

unread,
Mar 7, 2011, 3:29:58 PM3/7/11
to
There are two other points that might be helpful.

1) In the compute dialog, the Type & Label subdialog includes the choice to use the compute formula as the variable label.

2) If you use programmability, there is a module named Transform that will automatically create a custom attribute containing the formula. The formula is saved with the data and can be reexecuted, also by programmability code. This supports COMPUTE, RECODE, and COUNT, including DO IF blocks. This feature is only intended for those using Python programmabity, however.

HTH,
Jon Peck

MG

unread,
Mar 8, 2011, 11:20:19 AM3/8/11
to
> bwea...@lakeheadu.cahttp://sites.google.com/a/lakeheadu.ca/bweaver/Home

> "When all else fails, RTFM."

Again thanks a lot for your help. I kinda get it now and was writing
all my calculations in syntaxeditor (I am calculating subscales of a
Symptom Checklist 90 (SCL90) questionnaire). And it looks like it
works and my formulas are saved.

The next issue is that a part of the formula is to divide the result
with the amount of answered items
Say
Index1=item1+item2+item4+item8
and then it should be divided by 4 - that is as long as all 4 items
are answered. If only three of the items are answered then it should
be divided by 3.

Can I make a count like "count if" or how is this done in syntax
editor?


Again I don't think I can thank you enough and I might be pulling my
luck here, but it is pretty hard to get help regarding this elsewhere.


Thanks.

Bruce Weaver

unread,
Mar 8, 2011, 11:45:02 AM3/8/11
to
On Mar 8, 11:20 am, MG <spamawa...@gmail.com> wrote:

--- snip ---

>
> Again thanks a lot for your help. I kinda get it now and was writing
> all my calculations in syntaxeditor (I am calculating subscales of a
> Symptom Checklist 90 (SCL90) questionnaire). And it looks like it
> works and my formulas are saved.
>
> The next issue is that a part of the formula is to divide the result
> with the amount of answered items
> Say
> Index1=item1+item2+item4+item8
> and then it should be divided by 4 - that is as long as all 4 items
> are answered. If only three of the items are answered then it should
> be divided by 3.
>
> Can I make a count like "count if" or how is this done in syntax
> editor?
>
> Again I don't think I can thank you enough and I might be pulling my
> luck here, but it is pretty hard to get help regarding this elsewhere.
>
> Thanks.

Rather than compute a sum and divide by some N, just use one of the
MEAN functions. Here are a couple examples from the Help files.

COMPUTE MeanValue = MEAN(V1,V2,V3,V4).
COMPUTE NewMean = MEAN.3(V1,V2,V3,V4).

• MeanValue is the mean of the values for V1 to V4. Since the mean can
be computed for one, two, three, or four values, MeanValue is assigned
a valid value as long as any one of the four variables has a valid
value for that case.

• In the last example above, the .3 suffix specifies the minimum
number of valid arguments required. NewMean is the mean of variables
V1 to V4 only if at least three of these variables have valid values.
Otherwise, NewMean is system-missing for that case.

Note that if the variables are contiguous in the file, you could use
the key word TO rather than having to list all variables. I.e.,

COMPUTE MeanValue = MEAN(V1 to V4).
COMPUTE NewMean = MEAN.3(V1 to V4).


HTH.

--
Bruce Weaver
bwe...@lakeheadu.ca

MG

unread,
Mar 11, 2011, 3:57:36 AM3/11/11
to
> bwea...@lakeheadu.cahttp://sites.google.com/a/lakeheadu.ca/bweaver/Home

> "When all else fails, RTFM."

Thank you for this. Interesting though that I didn't think about it as
means. Would there be away to count the number of filled out items
anyway? I guess there is but where can I find it (aaaand now it would
be embarrassing if you refer me to the help files again :-/).

Thanks anyway


Cheers,

Bruce Weaver

unread,
Mar 11, 2011, 2:55:05 PM3/11/11
to

It's not always easy knowing where to look in the Help files until
after you've figured something out. Here's what you want:

NMISS. NMISS(variable[,..]). Numeric. Returns a count of the arguments
that have system- and user-missing values. This function requires one
or more arguments, which should be variable names in the active
dataset.

NVALID. NVALID(variable[,..]). Numeric. Returns a count of the
arguments that have valid, nonmissing values. This function requires
one or more arguments, which should be variable names in the active
dataset.

If you hand the same list of variables to NMISS and NVALID, the sum of
those two counts gives the total number of variables in the list.

--
Bruce Weaver
bwe...@lakeheadu.ca

Message has been deleted

Rich Ulrich

unread,
May 16, 2014, 2:07:09 AM5/16/14
to
On Thu, 15 May 2014 13:23:37 -0700 (PDT), lef...@gmail.com wrote:

>I still have not understand how I can check the variables I have computed in spss(into a statistical mean). I am a learner, so can anyone show me an easy way to find out and check the statistical mean prosthesis (to find out if I used the rights variables)?

"...prosthesis" makes me conclude that English is not
your native language.

If you want to know that a mean is correct for some data,
(a) read the code closely, and
(b) provide some test data with extremes: all 1's; all 1's but a
variable or two; a set of widely different numbers. And check
the arithmetic by hand.

--
Rich Ulrich
0 new messages