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

[Syntax] Convert between value labels and values

522 views
Skip to first unread message

Andreas Jaeger

unread,
Jul 14, 2010, 5:13:47 AM7/14/10
to
DATA LIST FREE ("-", ":")
/name (A10) gender (F1.0) points (F3.0).
BEGIN DATA
Sarah - 1 : 98
Paul - 2 : 87
END DATA.
VALUE LABELS gender
1 "female"
2 "male".
EXECUTE.

* Version 1: Does not work
SELECT IF (gender = "female").
EXECUTE.

* Version 2: Does work
SELECT IF (gender = 1).
EXECUTE.

For clarity, and to avoid typing/lookup errors, I'd prefer to express
comparisons via value labels rather than numeric codes. Any hints how to
achieve this?

P.S. The example is, of course, made up. I get the data from a larger
database that uses numbers to encode nominal values.

--
Andreas Jaeger
MMF GmbH, Herdecke, Germany
(Mail: use my surname at domain supplied)

peter m sopp

unread,
Jul 14, 2010, 7:26:11 AM7/14/10
to
Use STRING (here: A6) instead of numeric (F1.0):
...
/name (A10) gender (A6) points(F3.0)
...
Sarah - female : 98
Paul - male : 87
...

Another way:
STRING sex (A6).
RECODE gender (1 = "male")(2 = "female") INTO sex.
(Hope it works ...)

Peter Sopp

Andreas Jaeger

unread,
Jul 14, 2010, 8:24:21 AM7/14/10
to
On 14.07.2010 13:26, peter m sopp wrote:
> Use STRING (here: A6) instead of numeric (F1.0):

Well that surely works, but is not what I desire. Because I do have
numeric codes, I cannot redesign the data import. And I do not want to
recode the numeric codes into strings, either, because that would mean
to write down all the value label associations.

The intention is to work with enumeration names instead of numbers, as
it is much more secure (and even works after changing the codes). The
following is more prone to errors, and less stable

DO IF (gender = 1).
COMPUTE menopause = "n/a".
ELSE IF (age_category >= 4).
COMPUTE menopause = "yes".
ELSE.
COMPUTE menopause = "no".
END IF.

than this version

DO IF (gender = "male").
COMPUTE menopause = "n/a".
ELSE IF (age_category >= "old").
COMPUTE menopause = "yes".
ELSE.
COMPUTE menopause = "no".
END IF.

Andreas Jaeger

unread,
Jul 14, 2010, 8:28:43 AM7/14/10
to
On 14.07.2010 14:24, Andreas Jaeger wrote:

> DO IF (gender = "male").
> COMPUTE menopause = "n/a".
> ELSE IF (age_category >= "old").
> COMPUTE menopause = "yes".
> ELSE.
> COMPUTE menopause = "no".
> END IF.

As the above does not work, I'm looking for something along the lines of

DO IF (LBL(gender) = "male").


COMPUTE menopause = "n/a".

ELSE IF (age_category >= VAL("old")).

Andy W

unread,
Jul 14, 2010, 8:48:35 AM7/14/10
to
Replace LBL in the above syntax with the command VALUELABEL. I was
going to say you couldn't do it any other way than Peter suggested but
looking through the transform data list I found that command and was
able to use it within an if statement.

good luck
Andy W

Rich Ulrich

unread,
Jul 14, 2010, 4:33:19 PM7/14/10
to
On Wed, 14 Jul 2010 14:28:43 +0200, Andreas Jaeger
<nos...@mmf-herdecke.de> wrote:

>On 14.07.2010 14:24, Andreas Jaeger wrote:
>
>> DO IF (gender = "male").
>> COMPUTE menopause = "n/a".
>> ELSE IF (age_category >= "old").
>> COMPUTE menopause = "yes".
>> ELSE.
>> COMPUTE menopause = "no".
>> END IF.
>
>As the above does not work, I'm looking for something along the lines of
>
>DO IF (LBL(gender) = "male").
> COMPUTE menopause = "n/a".
>ELSE IF (age_category >= VAL("old")).

- without a clever, context-sensitive IF, that function
for VAL would have to say VAL("age_category", "old").

> COMPUTE menopause = "yes".
>ELSE.
> COMPUTE menopause = "no".
>END IF.

( I think of that sort of language processing as being
a feature of LISP, say. I don't think of it as being part of
any stat-pack, yet. That could be nice for documenting,
but I imagine that it is some years in the future.)

What occurs to me is that you might set up a
number of "constants", though SPSS does not lend
itself to that practice very readily. For instance,

COMPUTE male= 1.
COMPUTE female= 2.
COMPUTE yes=1.
compute no= 2.
compute m_age= 50.

... and then you can carry out your tests
and assignments using the variables.

NOTES.
- I would not want to assign my new variables,
like menopause, to have names that are literals,
rather than numbers. That is highly inconvenient for
most of the procedures. (Menopause example, above.)

- This becomes unsafe if there are different values
needed for "Male" or "yes" , etc., depending on which
question is asked. Then you could use the ad-hoc
adjustment of having m_yes, or whatever; but that is
something else to lose track of.

- To keep the assignments from being carried out for
every case, you *could* start every name with a "#"
and use a DO IF <case 1> to introduce the set of
computations that assign permanent values. #yes will
keep the same value on the second case, if it is not
redefined. (I'm assuming that this obscure feature still
exists.) Distinguishing these effective "constants" by
a peculiar prefix would also be a virtue for reading the
program, in the long run.


--
Rich Ulrich

0 new messages