syntax problem

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

syntax problem

Sebastián Daza
list,
I have had problems with the calculation of variables with conditions. for example in spss 15:

do if (var1=101).
comp x=sum (a1, z3).
end if.
exe.

the program calculates values when the variable a1 and z3 are 0. Why does this happen? What problem is there in the program?

some idea? regards.

--
Sebastián Daza Aranzaes

Sebastián Daza Aranzaes
Instituto de Sociología UC
8-471 53 87 / 686 57 20 / Fax 5521834
[hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: syntax problem

Hector Maletta
Sebastian,

Your formulation is unclear. Perhaps what you are saying is that some
non-zero value results from the COMPUTE even when a1=0 and z3=0. This may be
the case when a1 is not exactly zero but you have set the visible decimals
to none. Suppose a1=0.20, but the format is F1.0. In that case a1 would
appear as 0, but the actual value is 0.20, rounded to zero. At the same
time, the new variable X is probably created by default with two decimals,
and thus its value may reflect the decimals in a1 (and possibly in z3).

 

Besides, you do not need the DO IF either. Here is a simpler version:

 

IF (VAR1=101) X=SUM(A1,Z3).

If you so wish, the alternative version would be:

IF (VAR1=101 and A1 NE 0 AND Z3 NE 0) X=SUM(A1,Z3).

 

 

Hector

 

  _____  

From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Sebastián Daza
Sent: 16 June 2007 21:52
To: [hidden email]
Subject: syntax problem

 

list,
I have had problems with the calculation of variables with conditions. for
example in spss 15:

do if (var1=101).
comp x=sum (a1, z3).
end if.
exe.

the program calculates values when the variable a1 and z3 are 0. Why does
this happen? What problem is there in the program?

some idea? regards.

--



Sebastián Daza Aranzaes
Instituto de Sociología UC
8-471 53 87 / 686 57 20 / Fax 5521834
[hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: syntax problem

Sebastián Daza
hector,
the problem that I have happens me in some occasions. I have checked that it is an error of the program. I sometimes have to restart the program so that the syntax runs well. the same thing happens me to the command if, the sum of two variables that are 0 is 254. I don't know if it is a problem of the memory or other. has it happened you something similar?

regards.

--
Sebastián Daza Aranzaes

Sebastián Daza Aranzaes
Instituto de Sociología UC
8-471 53 87 / 686 57 20 / Fax 5521834
[hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: syntax problem

Hector Maletta
Never happened to me, I’m afraid. Quite strange. But since the syntax runs
well after you restart, it may have something to do with the previous
operations you have run before that one.

 

Hector

 

  _____  

From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Sebastián Daza
Sent: 16 June 2007 22:46
To: [hidden email]
Subject: Re: syntax problem

 

hector,
the problem that I have happens me in some occasions. I have checked that it
is an error of the program. I sometimes have to restart the program so that
the syntax runs well. the same thing happens me to the command if, the sum
of two variables that are 0 is 254. I don't know if it is a problem of the
memory or other. has it happened you something similar?

regards.

--



Sebastián Daza Aranzaes
Instituto de Sociología UC
8-471 53 87 / 686 57 20 / Fax 5521834
[hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: syntax problem

Art Kendall-2
In reply to this post by Sebastián Daza
There is example syntax below the sig block.

Save all your current work, then open a new instance of SPSS. Make sure
that you put warnings, etc. into the output file. <edit> <options>
<viewer>. Cut-and-paste then run the syntax.
Does this show what is causing the problem? If not please adapt the
example syntax so that it shows the problem occurring.

Hope this helps.

Art
[hidden email]
Social Research Consultants



data list list /var1 (f5.1) z1 (f4.1) middle (f3) a3 (f7.5).
begin data
101 1 999 2
101 .0001 999 12
101 0 999 q
101 0 999 0
101 0 999 .1
101 .2 999 0
101 1 999 240
101.1 1 999 2
101 1 888 2
101 1 999 2
102 1 999 1
end data.
missing values z1 a3 (0) middle (888).
numeric x1 to x3 (f9.5).
compute x1 = -999.
compute x2 = -999.
compute x3 = -999.
if var1 eq 101 x1 = z1 + a3.
if var1 eq 101 x2 = sum(z1,a3).
if var1 eq 101 x3 = sum.1(z1,a3).
value labels x1 to x3 -999 'not summed'.
var labels
  x1 ' just add the two numbers'
  x2 ' original sum function'
  x3 ' sum if just one argument is present'.
list.





Sebastián Daza wrote:

> hector,
> the problem that I have happens me in some occasions. I have checked
> that it is an error of the program. I sometimes have to restart the
> program so that the syntax runs well. the same thing happens me to the
> command if, the sum of two variables that are 0 is 254. I don't know
> if it is a problem of the memory or other. has it happened you
> something similar?
>
> regards.
>
> --
>
> Sebastián Daza Aranzaes
> *Instituto de Sociología UC
> *8-471 53 87 / 686 57 20 / Fax 5521834
> [hidden email] <mailto:[hidden email]>
>
Reply | Threaded
Open this post in threaded view
|

Re: syntax problem

Art Kendall-2
If you open many files and then run the syntax I posted do you get the
problem?


Can you create a minimal subset of your data and syntax that has the
problem on some occasions?
If you set your output to "draft" you should have output that you can
cut-and paste to email.
Save the output file from a run that has the problem.

Are you GETting the data from a file on your local computer or from a
server?

Are you sure which is the active file when you run the syntax?

Art Kendall
Social Research Consultants

Sebastián Daza wrote:

> dear art,
> my problem is not of syntax. in some occasions I have the error, and I
> have to restart the program so it runs well. don't I understand why?
>
> I don't have defined missing. it is a big base.
>
> var var2 var3...  a1 varx vary.... z3
> 101                  0                     0
>
> if var=101 xx=sum (a1, z3).
>
> the results are clearly erroneous.
> will it be because I work with many bases opened up at the same time?
> the strange thing is that the erroneous values are added to the active
> dataset.
>
> regards.
>
>
> --
>
> Sebastián Daza Aranzaes
> *Instituto de Sociología UC
> *8-471 53 87 / 686 57 20 / Fax 5521834
> [hidden email] <mailto:[hidden email]>
>
Reply | Threaded
Open this post in threaded view
|

Re: syntax problem

Jerabek Jindrich
Hi Sebastián,

a reason why a syntax does not work and the program must be restarted could be:

We have defined a macro
And then used a syntax and dataset that has a variable named exaxtly as is the name of the macro.

It always ends with many surprising errors and is solved when the SPSS is restarted.

only an idea
regards Jindra


> ------------ Původní zpráva ------------
> Od: Art Kendall <[hidden email]>
> Předmět: Re: syntax problem
> Datum: 17.6.2007 19:20:16
> ----------------------------------------
> If you open many files and then run the syntax I posted do you get the
> problem?
>
>
> Can you create a minimal subset of your data and syntax that has the
> problem on some occasions?
> If you set your output to "draft" you should have output that you can
> cut-and paste to email.
> Save the output file from a run that has the problem.
>
> Are you GETting the data from a file on your local computer or from a
> server?
>
> Are you sure which is the active file when you run the syntax?
>
> Art Kendall
> Social Research Consultants
>
> Sebastián Daza wrote:
> > dear art,
> > my problem is not of syntax. in some occasions I have the error, and I
> > have to restart the program so it runs well. don't I understand why?
> >
> > I don't have defined missing. it is a big base.
> >
> > var var2 var3...  a1 varx vary.... z3
> > 101                  0                     0
> >
> > if var=101 xx=sum (a1, z3).
> >
> > the results are clearly erroneous.
> > will it be because I work with many bases opened up at the same time?
> > the strange thing is that the erroneous values are added to the active
> > dataset.
> >
> > regards.
> >
> >
> > --
> >
> > Sebastián Daza Aranzaes
> > *Instituto de Sociología UC
> > *8-471 53 87 / 686 57 20 / Fax 5521834
> > [hidden email] <mailto:[hidden email]>
> >
>
>
>