IF The expression ends unexpectedly

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

IF The expression ends unexpectedly

ECL
Hi all

I am completely new to syntax.

Could someone please point me in the right directiohn as to why I get the error "IF The expression ends unexpectedly. Execution of this command stops"?

Compute c1=1
IF Q41>2 & (Q43=0 OR Q43=2)&Q45=1&((Q46>0&(Q47>0 OR Q48>0)) OR (Q46>0&(Q49>0 OR Q50>0)) OR   ((Q47>0 OR Q48>0)&(Q49>0 OR Q50>0)))
Execute.
Reply | Threaded
Open this post in threaded view
|

Re: IF The expression ends unexpectedly

Maguin, Eugene
You know, you have to win the secret competition for the most complicated IF expression I have ever, ever, seen. I score it 10 of 10 on complexity!

I counted parentheses and I think that number is an even number but I'm not sure that they are balanced.
That aside, three specific problems. 1) No period at the end of the compute statement. 2) No period at the end of the if statement. 3) The if statement does not do anything. So, what if the statement is true, then what???
Gene Maguin

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of ECL
Sent: Tuesday, May 06, 2014 11:20 PM
To: [hidden email]
Subject: IF The expression ends unexpectedly

Hi all

I am completely new to syntax.

Could someone please point me in the right directiohn as to why I get the error "IF The expression ends unexpectedly. Execution of this command stops"?

Compute c1=1
IF Q41>2 & (Q43=0 OR Q43=2)&Q45=1&((Q46>0&(Q47>0 OR Q48>0)) OR (Q46>0&(Q49>0
OR Q50>0)) OR   ((Q47>0 OR Q48>0)&(Q49>0 OR Q50>0)))
Execute.



--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/IF-The-expression-ends-unexpectedly-tp5725852.html
Sent from the SPSSX Discussion mailing list archive at 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
ECL
Reply | Threaded
Open this post in threaded view
|

Re: IF The expression ends unexpectedly

ECL
Hi Gene

I'm tearing my hair out!!!

Umm, IF all those are present then you have a disese :).  Unfortunately, that is one of the simpler formulas I have :(.

I'm trying to say that IF......then C1=1.  SHould I have C1=1 after the IF statement rather than before?

I will correct those other problems, thankyou.
How on earth did you all learn this?

Kind regards
Ecushla
ECL
Reply | Threaded
Open this post in threaded view
|

Re: IF The expression ends unexpectedly

ECL
In reply to this post by Maguin, Eugene
Possibly getting closer? But still not correct.

Compute C1=0
Compute
IF[ Q41>2 & (Q43=0 OR Q43=2) & Q45=1 & ((Q46>0 & (Q47>0 OR Q48>0)) OR (Q46>0 &
 (Q49>0 OR Q50>0)) OR ((Q47>0 OR Q48>0) & (Q49>0 OR Q50>0)))] C1=1.

>Error # 4381 in column 1.  Text: Compute
>The expression ends unexpectedly.
>Execution of this command stops.
Execute.
Reply | Threaded
Open this post in threaded view
|

Re: IF The expression ends unexpectedly

Mark Miller
Perhaps this will work

IF    (    Q41  >  2  
& (Q43 = 0 OR Q43 = 2)
&  Q45 = 1  
& (       (  Q46 > 0 & ( Q47 > 0 OR Q48 > 0) ) 
OR (  Q46 > 0 & ( Q49 > 0 OR Q50 > 0) ) 
OR (  (Q47 > 0 OR Q48 > 0)  &  (Q49 > 0 OR Q50 > 0)  )
)
     c1 = 1.


... mark Miller


On Tue, May 6, 2014 at 9:27 PM, ECL <[hidden email]> wrote:
Possibly getting closer? But still not correct.

Compute C1=0
Compute
IF[ Q41>2 & (Q43=0 OR Q43=2) & Q45=1 & ((Q46>0 & (Q47>0 OR Q48>0)) OR (Q46>0
&
 (Q49>0 OR Q50>0)) OR ((Q47>0 OR Q48>0) & (Q49>0 OR Q50>0)))] C1=1.

>Error # 4381 in column 1.  Text: Compute
>The expression ends unexpectedly.
>Execution of this command stops.
Execute.




--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/IF-The-expression-ends-unexpectedly-tp5725852p5725856.html
Sent from the SPSSX Discussion mailing list archive at 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

ECL
Reply | Threaded
Open this post in threaded view
|

Re: IF The expression ends unexpectedly

ECL
Thanks Mark

I tried that, but it still wants an equals sign somewhere?
I guess on the bright side, once I work out this one, all the rest will use
the same rules.

Compute C1=0.
Compute
 IF (Q41>2)
& (Q43=0 OR Q43=2)
& Q45=1
& ((Q46>0 & (Q47>0 OR Q48>0))
OR (Q46>0 & (Q49>0 OR Q50>0))
OR ((Q47>0 OR Q48>0) & (Q49>0 OR Q50>0))) c1=1
Execute.

>Error # 4382 in column 1.  Text: &
>An equals sign was not found when expected after a target variable in a
>COMPUTE command.
>Execution of this command stops.




--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/IF-The-expression-ends-unexpectedly-tp5725852p5725858.html
Sent from the SPSSX Discussion mailing list archive at 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: IF The expression ends unexpectedly

Mark Miller
Drop the COMPUTE statements -- you do not need them.

... mark


On Tue, May 6, 2014 at 9:52 PM, ECL <[hidden email]> wrote:
Thanks Mark

I tried that, but it still wants an equals sign somewhere?
I guess on the bright side, once I work out this one, all the rest will use
the same rules.

Compute C1=0.
Compute
 IF (Q41>2)
& (Q43=0 OR Q43=2)
& Q45=1
& ((Q46>0 & (Q47>0 OR Q48>0))
OR (Q46>0 & (Q49>0 OR Q50>0))
OR ((Q47>0 OR Q48>0) & (Q49>0 OR Q50>0))) c1=1
Execute.

>Error # 4382 in column 1.  Text: &
>An equals sign was not found when expected after a target variable in a
>COMPUTE command.
>Execution of this command stops.




--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/IF-The-expression-ends-unexpectedly-tp5725852p5725858.html
Sent from the SPSSX Discussion mailing list archive at 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

ECL
Reply | Threaded
Open this post in threaded view
|

Re: IF The expression ends unexpectedly

ECL
Thank you Mark!!

That works :).

VERY MUCH APPRECIATED.
Reply | Threaded
Open this post in threaded view
|

Re: IF The expression ends unexpectedly

Rich Ulrich
In reply to this post by ECL
Especially if you will be doing a bunch of these, it probably is
useful to compute some temporary variables for the things that are
reused.  Or (even), just for clarity.   The result of a logical comparison
is 0/1, so

COMPUTE  #GT4748= (Q47>0 OR Q48>0).
COMPUTE   #GT4950= (Q49>0 OR Q50>0).
Compute C1=
   (Q41>2)  & (Q43=0 OR Q43=2) & Q45=1
  & ( (Q46>0 & #GT4748)
  OR (Q46>0 & #GT4950)
  OR (#GT4748 & #GT4950) ).

If you replace all of your separate logical tests with temporary variables,
labeled GT for greater than, EQ for equal, the more-readable result is

Compute C1= #GT41 & #EQ43 & #EQ45
  &( (#GT46 & #GT4748)
  OR (#GT46 & #GT4950)
  OR (#GT4758 & #GT4950) ).

If it helps you generalize, you could combine (say) lines 2 and 3.
Or, since the values are 0/1, you can combine lines 2,3,4  by the
condition implied in the code, that at least two of them are "1" --
  &( (#GT46 + #GT4748 + #GT4950) GE 2) .

I think I kept track of the parentheses correctly.

--
Rich Ulrich

> Date: Tue, 6 May 2014 21:52:06 -0700
> From: [hidden email]
> Subject: Re: IF The expression ends unexpectedly
> To: [hidden email]
>
> Thanks Mark
>
> I tried that, but it still wants an equals sign somewhere?
> I guess on the bright side, once I work out this one, all the rest will use
> the same rules.
>
> Compute C1=0.
> Compute
> IF (Q41>2)
> & (Q43=0 OR Q43=2)
> & Q45=1
> & ((Q46>0 & (Q47>0 OR Q48>0))
> OR (Q46>0 & (Q49>0 OR Q50>0))
> OR ((Q47>0 OR Q48>0) & (Q49>0 OR Q50>0))) c1=1
> Execute.
>
> >Error # 4382 in column 1. Text: &
> >An equals sign was not found when expected after a target variable in a
> >COMPUTE command.
> >Execution of this command stops.
>
>
>
>
> --
> View this message in context: http://spssx-discussion.1045642.n5.nabble.com/IF-The-expression-ends-unexpectedly-tp5725852p5725858.html
> Sent from the SPSSX Discussion mailing list archive at 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: IF The expression ends unexpectedly

David Marso
Administrator
In reply to this post by ECL
Does this do what you expect?
Compute C1 = (Q41 GT 2)
 & ANY(Q43,0,2) & (Q45 EQ 1) & (Q46 GT 0 & SUM(0,Q47 TO Q50) GT 0)
 OR (SUM(0,Q47,Q48) * SUM(0,Q49,Q50)) GT 0.

ECL wrote
Thank you Mark!!

That works :).

VERY MUCH APPRECIATED.
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: IF The expression ends unexpectedly

Art Kendall
In reply to this post by ECL
Your compute statement does not has a period.
if you are trying to create a flag variable via COMPUTE
compute flag = condition.
the IF is implicit.

an IF statement has 2 major parts
the condition
a transformation.
if condition compute x =1.

There is nothing that says what to do if the condition is true.
(In SAS an incomplete IF is a SELECT IF.)

you would help readability for yourself, QA reviewers, maintainers, etc. if you prettied it up and perhaps broke it up into several lines.
IF
Q41 gt 2 and
(Q43 eq 0 OR Q43 eq 2) and
Q45 eq 1 and
((Q46 gt 0 and (Q47 gt 0 OR Q48 gt 0)) OR
(Q46 gt 0and(Q49 gt 0 OR Q50 gt 0)) OR
((Q47 gt 0 OR Q48 gt 0) and (Q49 gt 0 OR Q50 gt 0)))
compute x = 1.




Fro curiosity, why do you need such a complex condition
Art Kendall
Social Research Consultants
On 5/6/2014 11:20 PM, ECL [via SPSSX Discussion] wrote:
Hi all

I am completely new to syntax.

Could someone please point me in the right directiohn as to why I get the error "IF The expression ends unexpectedly. Execution of this command stops"?

Compute c1=1
IF Q41>2 & (Q43=0 OR Q43=2)&Q45=1&((Q46>0&(Q47>0 OR Q48>0)) OR (Q46>0&(Q49>0 OR Q50>0)) OR   ((Q47>0 OR Q48>0)&(Q49>0 OR Q50>0)))
Execute.


If you reply to this email, your message will be added to the discussion below:
http://spssx-discussion.1045642.n5.nabble.com/IF-The-expression-ends-unexpectedly-tp5725852.html
To start a new topic under SPSSX Discussion, email [hidden email]
To unsubscribe from SPSSX Discussion, click here.
NAML

Art Kendall
Social Research Consultants
ECL
Reply | Threaded
Open this post in threaded view
|

Re: IF The expression ends unexpectedly

ECL
Hi Art

Thank you for that information, that makes sense.

This is a scoring system to distinguish between different medical conditions based on patient a answers to 80 or so questions. I can't really think of any other way to set up an automatic scoring system. 






On 7 May 2014, at 9:07 pm, "Art Kendall [via SPSSX Discussion]" <[hidden email]> wrote:

Your compute statement does not has a period.
if you are trying to create a flag variable via COMPUTE
compute flag = condition.
the IF is implicit.

an IF statement has 2 major parts
the condition
a transformation.
if condition compute x =1.

There is nothing that says what to do if the condition is true.
(In SAS an incomplete IF is a SELECT IF.)

you would help readability for yourself, QA reviewers, maintainers, etc. if you prettied it up and perhaps broke it up into several lines.
IF
Q41 gt 2 and
(Q43 eq 0 OR Q43 eq 2) and
Q45 eq 1 and
((Q46 gt 0 and (Q47 gt 0 OR Q48 gt 0)) OR
(Q46 gt 0and(Q49 gt 0 OR Q50 gt 0)) OR
((Q47 gt 0 OR Q48 gt 0) and (Q49 gt 0 OR Q50 gt 0)))
compute x = 1.




Fro curiosity, why do you need such a complex condition
Art Kendall
Social Research Consultants
On 5/6/2014 11:20 PM, ECL [via SPSSX Discussion] wrote:
Hi all

I am completely new to syntax.

Could someone please point me in the right directiohn as to why I get the error "IF The expression ends unexpectedly. Execution of this command stops"?

Compute c1=1
IF Q41>2 & (Q43=0 OR Q43=2)&Q45=1&((Q46>0&(Q47>0 OR Q48>0)) OR (Q46>0&(Q49>0 OR Q50>0)) OR   ((Q47>0 OR Q48>0)&(Q49>0 OR Q50>0)))
Execute.


If you reply to this email, your message will be added to the discussion below:
http://spssx-discussion.1045642.n5.nabble.com/IF-The-expression-ends-unexpectedly-tp5725852.html
To start a new topic under SPSSX Discussion, email [hidden email]
To unsubscribe from SPSSX Discussion, click here.
NAML

Art Kendall
Social Research Consultants



If you reply to this email, your message will be added to the discussion below:
http://spssx-discussion.1045642.n5.nabble.com/IF-The-expression-ends-unexpectedly-tp5725852p5725866.html
To unsubscribe from IF The expression ends unexpectedly, click here.
NAML
Reply | Threaded
Open this post in threaded view
|

Re: IF The expression ends unexpectedly

kwame woei
Read the Universals section in the manual. It's a dirty job, but it will get you up to speed with the Command Syntax.

Op 7 mei 2014 om 13:42 heeft "ECL" <[hidden email]> het volgende geschreven:

Hi Art

Thank you for that information, that makes sense.

This is a scoring system to distinguish between different medical conditions based on patient a answers to 80 or so questions. I can't really think of any other way to set up an automatic scoring system. 






On 7 May 2014, at 9:07 pm, "Art Kendall [via SPSSX Discussion]" <[hidden email]> wrote:

Your compute statement does not has a period.
if you are trying to create a flag variable via COMPUTE
compute flag = condition.
the IF is implicit.

an IF statement has 2 major parts
the condition
a transformation.
if condition compute x =1.

There is nothing that says what to do if the condition is true.
(In SAS an incomplete IF is a SELECT IF.)

you would help readability for yourself, QA reviewers, maintainers, etc. if you prettied it up and perhaps broke it up into several lines.
IF
Q41 gt 2 and
(Q43 eq 0 OR Q43 eq 2) and
Q45 eq 1 and
((Q46 gt 0 and (Q47 gt 0 OR Q48 gt 0)) OR
(Q46 gt 0and(Q49 gt 0 OR Q50 gt 0)) OR
((Q47 gt 0 OR Q48 gt 0) and (Q49 gt 0 OR Q50 gt 0)))
compute x = 1.




Fro curiosity, why do you need such a complex condition
Art Kendall
Social Research Consultants
On 5/6/2014 11:20 PM, ECL [via SPSSX Discussion] wrote:
Hi all

I am completely new to syntax.

Could someone please point me in the right directiohn as to why I get the error "IF The expression ends unexpectedly. Execution of this command stops"?

Compute c1=1
IF Q41>2 & (Q43=0 OR Q43=2)&Q45=1&((Q46>0&(Q47>0 OR Q48>0)) OR (Q46>0&(Q49>0 OR Q50>0)) OR   ((Q47>0 OR Q48>0)&(Q49>0 OR Q50>0)))
Execute.


If you reply to this email, your message will be added to the discussion below:
http://spssx-discussion.1045642.n5.nabble.com/IF-The-expression-ends-unexpectedly-tp5725852.html
To start a new topic under SPSSX Discussion, email [hidden email]
To unsubscribe from SPSSX Discussion, click here.
NAML

Art Kendall
Social Research Consultants



If you reply to this email, your message will be added to the discussion below:
http://spssx-discussion.1045642.n5.nabble.com/IF-The-expression-ends-unexpectedly-tp5725852p5725866.html
To unsubscribe from IF The expression ends unexpectedly, click here.
NAML


View this message in context: Re: IF The expression ends unexpectedly
Sent from the SPSSX Discussion mailing list archive at Nabble.com.
Reply | Threaded
Open this post in threaded view
|

Re: IF The expression ends unexpectedly

PRogman
In reply to this post by ECL
Is there any missing values among the variables in the IF statement? If so the c1 will also be missing, unless David Marcos suggesstion is used. A solution with the statistical function SUM(0,...) will always compute to 0 or 1, as missing values are computed to 0. Also, with such a complicated expression I suggest using comments and indentation to clarify the logic. In my programming style I always keep logical expression within parenthesis (and prefer AND, OR, NOT) to make them different from assignments.
IF ((Q41>2) &                                  /* Cond 1  AND */
    ((Q43=0) OR (Q43=2)) &                     /* Cond 2  AND */
    (Q45=1) &                                  /* Cond 3  AND */
    (((Q46>0) & ((Q47>0) | (Q48>0))) |         /* Cond 4a OR  */  
     ((Q46>0) & ((Q49>0) | (Q50>0))) |         /* Cond 4b OR  */   
     ((Q47>0 | Q48>0) & ((Q49>0) | (Q50>0)))   /* Cond 4c     */
    )                                          /* >Set Flag c1*/
   ) c1=1.
or maybe modified Marso Code (where only a missing Q43 will make c1 missing)
Compute C1 = ((SUM(0, Q41) GT 2)  AND  /* cond 1 */
              (ANY(Q43, 0, 2))    AND  /* cond 2 */
              (SUM(0, Q45) EQ 1)  AND  /* cond 3 */
              ((SUM(0, Q46) GT 0) AND (SUM(0, Q47 TO Q50) GT 0)) OR 
               ((SUM(0, Q47, Q48)*SUM(0, Q49, Q50)) GT 0)  /* cond 4 */
ECL
Reply | Threaded
Open this post in threaded view
|

Re: IF The expression ends unexpectedly

ECL
Hi Progman

Thank you for your reply.  

I cannot use SUM function as that is not the calculation I am after.
However I like your clear comments on the right.

Do you mean I would write it like this?

/* Q41>2 AND */
/* (Q43=0) OR (Q43=2) AND*/
ETC


Also how does the '>Set Flag C1' differ from C1=1 Execute?

Appreciate everyone's comments.  I will try and find this manual someone suggested. I have downloaded a few already but they seem to be of no use.
ECL
Reply | Threaded
Open this post in threaded view
|

Re: IF The expression ends unexpectedly

ECL
In reply to this post by David Marso
Hi David

Thanks for your reply.

I've finally worked out why you suggest the SUM function for some of these.
However in this particular diagnosis I need  

(Q41 GT 2) AND ANY (Q43, 0,2)
and then "2 or more of the following three options'' below ( I don't know whether its possible to do that).

(Q46 GT 0)

(SUM (0, Q47, Q48) GT 0 (does this mean the sum of Q47 and Q48 is  gt zero).

(SUM (0, Q49, 50) GT 0


Compute C1 = (Q41 GT 2)
 & ANY(Q43,0,2) & (Q45 EQ 1) & (Q46 GT 0 & SUM(0,Q47 TO Q50) GT 0)
 OR (SUM(0,Q47,Q48) * SUM(0,Q49,Q50)) GT 0.
Reply | Threaded
Open this post in threaded view
|

Re: IF The expression ends unexpectedly

David Marso
Administrator
"(SUM (0, Q47, Q48) GT 0 (does this mean the sum of Q47 and Q48 is  gt zero). "
Yes!
My only purpose in having the 0 in the expression is to avoid calamity in case both terms were missing.
Missing values often produce counter intuitive results unless extra care is taken.
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
ECL
Reply | Threaded
Open this post in threaded view
|

Re: IF The expression ends unexpectedly

ECL
David Marso wrote
"My only purpose in having the 0 in the expression is to avoid calamity in case both terms were missing.
Missing values often produce counter intuitive results unless extra care is taken.
That sounds like a very important inclusion then! Tx