Discussion:
How use shorthand to recompute into single variable after CASETOVARS?
(too old to reply)
b***@gmail.com
2019-10-17 20:58:15 UTC
Permalink
I am de-duplicating a large data set using CASETOVARS.

Because I have up to 24 duplicates in the data set, after I combine, each of my other variables becomes 24 new variables. For example:

The single variable "pregnant" becomes "pregnant.1", "pregnant.2",..."pregnant.24".

I want to recombine these to a single variable so that if any of the variables "pregnant.1" through "pregnant.24" = 1, a new variable pregnant=1 is created. To do this I have to manually write length code like this:

IF ((pregnant.1 = 1) OR (pregnant.2 = 1) OR (pregnant.3 = 1) OR (pregnant.4 = 1) OR (pregnant.5 = 1) OR (pregnant.6 = 1) OR (pregnant.7 = 1) OR (pregnant.8 = 1) OR (pregnant.9 = 1) OR (pregnant.10 = 1.....pregnant.24 = 1)) pregnant = 1.

Every time I run a new dataset, I will have a different number of these new variables, so I am wondering if there is a shorthand to create a new variable like I could do in R.

For example:

IF (pregnant.1:24 = 1) pregnant=1.


Thanks.
Rich Ulrich
2019-10-18 01:22:53 UTC
Permalink
Post by b***@gmail.com
I am de-duplicating a large data set using CASETOVARS.
The single variable "pregnant" becomes "pregnant.1", "pregnant.2",..."pregnant.24".
IF ((pregnant.1 = 1) OR (pregnant.2 = 1) OR (pregnant.3 = 1) OR (pregnant.4 = 1) OR (pregnant.5 = 1) OR (pregnant.6 = 1) OR (pregnant.7 = 1) OR (pregnant.8 = 1) OR (pregnant.9 = 1) OR (pregnant.10 = 1.....pregnant.24 = 1)) pregnant = 1.
Every time I run a new dataset, I will have a different number of these new variables, so I am wondering if there is a shorthand to create a new variable like I could do in R.
IF (pregnant.1:24 = 1) pregnant=1.
compute pregnant= any(1, pregnant.1 to pregnant.24).

ANY( ) compares the first argument to the remaining list.
ANY( ) returns 0 or 1 for No or Yes.

It is also used for checking multiple values for one variable,
like
compute anyodd= ANY(varxxx, 1, 3, 5, 7, 9) .

https://www.spss-tutorials.com/spss-any-function/
--
Rich Ulrich
Loading...