Simplifying Logic

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

Simplifying Logic

Egon Kraan
Dear Listers,


I am tying to compute a variable based on responses to other variables
but the logic is very complex and I was hoping I could get come help
here.


For example, I need to code GROUP = 1 if VAR1 is any of the following
values 1 - 4, 6 - 7, 10, 12, 14 - 15, and not 20.

I would write something like

if (( var1 ge 1 and  var1 le 4) or (var1 ge 6 and var1 le 7) or (var....
etc..

Is there a simpler way, something like

If (var1 IN(1 to 4, 6 to 7, 10, 12, 14 to 15) and (var1 ne 20)) seg = 1.


If not, is there some other way to simplify this?

Thanks

Egon

Egon Kraan
Research Associate, Project Analysis
TNS
600 Vine Street, Suite 300
Cincinnati, Ohio 45202

Phone:   (513) 345-6735
Fax:       (513) 461-7989
Email:    [hidden email]
Web:      www.tns-us.com
------------------------------------------------------------------------
----------------
This email and any files transmitted with it are confidential and
intended
solely for the use of the individual or entity to whom they are
addressed.
If you are not the addressee or authorized to receive this for the
addressee,
you must not use, copy, disclose or take any action based on this
message
or any information herein. If you have received this message in error,
please advise the sender immediately by reply e-mail and delete this
message. Thank you for your cooperation.
------------------------------------------------------------------------
----------------

====================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: Simplifying Logic

Spousta Jan
Hi Egon,

Try the RECODE command or the RANGE function which works almost exactly like you described.

Best regards

Jan

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Egon Kraan
Sent: Wednesday, April 16, 2008 4:48 PM
To: [hidden email]
Subject: Simplifying Logic

Dear Listers,


I am tying to compute a variable based on responses to other variables but the logic is very complex and I was hoping I could get come help here.


For example, I need to code GROUP = 1 if VAR1 is any of the following values 1 - 4, 6 - 7, 10, 12, 14 - 15, and not 20.

I would write something like

if (( var1 ge 1 and  var1 le 4) or (var1 ge 6 and var1 le 7) or (var....
etc..

Is there a simpler way, something like

If (var1 IN(1 to 4, 6 to 7, 10, 12, 14 to 15) and (var1 ne 20)) seg = 1.


If not, is there some other way to simplify this?

Thanks

Egon

Egon Kraan
Research Associate, Project Analysis
TNS
600 Vine Street, Suite 300
Cincinnati, Ohio 45202

Phone:   (513) 345-6735
Fax:       (513) 461-7989
Email:    [hidden email]
Web:      www.tns-us.com
------------------------------------------------------------------------
----------------
This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed.
If you are not the addressee or authorized to receive this for the addressee, you must not use, copy, disclose or take any action based on this message or any information herein. If you have received this message in error, please advise the sender immediately by reply e-mail and delete this message. Thank you for your cooperation.
------------------------------------------------------------------------
----------------

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



_____

Tato zpráva a všechny připojené soubory jsou důvěrné a určené výlučně adresátovi(-ům). Jestliže nejste oprávněným adresátem, je zakázáno jakékoliv zveřejňování, zprostředkování nebo jiné použití těchto informací. Jestliže jste tento mail dostali neoprávněně, prosím, uvědomte odesilatele a smažte zprávu i přiložené soubory. Odesilatel nezodpovídá za jakékoliv chyby nebo opomenutí způsobené tímto přenosem.

This message and any attached files are confidential and intended solely for the addressee(s). Any publication, transmission or other use of the information by a person or entity other than the intended addressee is prohibited. If you receive this in error please contact the sender and delete the message as well as all attached documents. The sender does not accept liability for any errors or omissions as a result of the transmission.

-.- --

=====================
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: Simplifying Logic

Egon Kraan
In reply to this post by Egon Kraan
Thanks to all who responded.

It seems like    IF ANY(var1, 1,2,3,4,5)   or   IF RANGE(var1, 1,5)  are
exactly what I was looking for.   I know I've used the RANGE to select
dates, so I should have figured it out eh?

Again, thanks

Egon

> _____________________________________________
> From:         Egon Kraan  
> Sent: Wednesday, April 16, 2008 10:48 AM
> To:   SPSSX-L ([hidden email])
> Subject:      Simplifying Logic
>
> Dear Listers,
>
>
> I am tying to compute a variable based on responses to other variables
> but the logic is very complex and I was hoping I could get come help
> here.
>
>
> For example, I need to code GROUP = 1 if VAR1 is any of the following
> values 1 - 4, 6 - 7, 10, 12, 14 - 15, and not 20.
>
> I would write something like
>
> if (( var1 ge 1 and  var1 le 4) or (var1 ge 6 and var1 le 7) or
> (var.... etc..
>
> Is there a simpler way, something like
>
> If (var1 IN(1 to 4, 6 to 7, 10, 12, 14 to 15) and (var1 ne 20)) seg =
> 1.
>
>
> If not, is there some other way to simplify this?
>
> Thanks
>
> Egon
>
> Egon Kraan
> Research Associate, Project Analysis
> TNS
> 600 Vine Street, Suite 300
> Cincinnati, Ohio 45202
>
> Phone:   (513) 345-6735
> Fax:       (513) 461-7989
> Email:    [hidden email]
> Web:      www.tns-us.com
> ----------------------------------------------------------------------
> ------------------
> This email and any files transmitted with it are confidential and
> intended
> solely for the use of the individual or entity to whom they are
> addressed.
> If you are not the addressee or authorized to receive this for the
> addressee,
> you must not use, copy, disclose or take any action based on this
> message
> or any information herein. If you have received this message in error,
>
> please advise the sender immediately by reply e-mail and delete this
> message. Thank you for your cooperation.
> ----------------------------------------------------------------------
> ------------------
>
>

====================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: Simplifying Logic

Richard Ristow
In reply to this post by Egon Kraan
At 10:48 AM 4/16/2008, Egon Kraan wrote:

>I am tying to compute a variable based on responses to other
>variables. For example, I need to code GROUP = 1 if VAR1 is any of
>the following values 1 - 4, 6 - 7, 10, 12, 14 - 15, and not 20.

At 11:05 AM 4/16/2008, Spousta Jan wrote:

>Try the RECODE command or the RANGE function [...]

Hear, hear. Especially RECODE, which is one of the most elegant
features of the transformation language. It will pay any SPSS user to
learn it thoroughly.

=====================
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: Simplifying Logic

Richard Ristow
In reply to this post by Egon Kraan
At 12:45 PM 4/16/2008, Egon Kraan wrote:

>>I need to code GROUP = 1 if VAR1 is any of the following values 1 -
>>4, 6 - 7, 10, 12, 14 - 15, and not 20.
>
>It seems like    IF ANY(var1, 1,2,3,4,5)   or   IF RANGE(var1,
>1,5)  are exactly what I was looking for.

Following up: Those certainly can work. But, also, be aware of

RECODE var1
    ( 1 THRU  4,
      6 THRU  7,
     10,
     12,
     14, 15     = 1)
     into GROUP.
*  Then, if desired, something like .
RECODE   GROUP (SYSMIS = 0).

LIST.
|-----------------------------|---------------------------|
|Output Created               |16-APR-2008 16:02:11       |
|-----------------------------|---------------------------|
var1    GROUP

    1     1.00
    2     1.00
    3     1.00
    4     1.00
    5      .00
    6     1.00
    7     1.00
    8      .00
    9      .00
   10     1.00
   11      .00
   12     1.00
   13      .00
   14     1.00
   15     1.00
   16      .00
   17      .00
   18      .00
   19      .00
   20      .00

Number of cases read:  20    Number of cases listed:  20
===================
APPENDIX: Test data
===================
NEW FILE.
INPUT PROGRAM.
.  NUMERIC var1 (F3).
.  LOOP    var1 = 1 TO 20.
.     END CASE.
.  END LOOP.
END FILE.
END INPUT PROGRAM.

.  /**/  LIST /*-*/.

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