Date: Fri, 5 May 2000 21:54:12 -0400
Reply-To: Raynald Levesque <rlevesque@VIDEOTRON.CA>
Sender: "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From: Raynald Levesque <rlevesque@VIDEOTRON.CA>
Subject: Re: Macro and data set variables
Content-type: text/plain; charset=iso-8859-1
Hi
The following syntax shows how to use
a value calculated from the data file as the end point of a !DO LOOP.
SET MPRINT=ON.
DATA LIST LIST /id(F8) var1(F8).
BEGIN DATA.
1 1
1 3
1 2
2 20
2 25
3 15
3 25
END DATA.
LIST.
SAVE OUTFILE='data.sav'.
COMPUTE break_v=(id=1).
AGGREGATE
/OUTFILE=*
/BREAK=break_v
/var1_1 = SUM(var1).
DO IF break_v=1.
WRITE OUTFILE 'temp.sps' /"DEFINE !sum_1()"/var1_1/"!ENDDEFINE.".
END IF.
EXE.
INCLUDE 'temp.sps'.
GET
FILE='data.sav'.
DEFINE !doit(nb_loop=!TOKENS(1))
!DO !cnt=1 !TO !nb_loop
COMPUTE !CONCAT(var,!cnt)=!cnt.
!DOEND
!ENDDEFINE
*The macro call uses as argument the macro sum_1 which was defined above.
!doit nb_loop=!sum_1.
EXECUTE.
After running the syntax you will see that variables var 1 to var6 have been
computed.
This was done with in the !DO loop where the end of the !DO loop is !nb_loop
which is itself the sum of the var1 variable in the original file.
Hope this is useful
Regards
Raynald Levesque rlevesque@videotron.ca
----- Original Message -----
From: Guilherme Coelho Rabello <gcoelho@inep.gov.br>
To: SPSS-Lista <SPSSX-L@UGA.CC.UGA.EDU>; Raynald Levesque
<rlevesque@VIDEOTRON.CA>
Sent: Friday, May 05, 2000 11:23 AM
Subject: RES: Macro and data set variables
> HI again.
>
> Thanks for the answer and for the very good solution. I had jut discovered
> that the problem occurs with the "do" statement. Acctualy I could put a
> variable value into a macro variable, but I could not use it in a "do"
macro
> statement :
>
> ...
> aggregate ...
> /qtd=nu
> ...
> !let !qtd=qtd.
> !do !i=1 !to !qtd.
> ...
> !doend.
> ...
>
> I get an erro message that SPSS expect a numeric value in a macro
> statemenet. Thanks,
>
> Guilherme.
>
> -----Mensagem original-----
> De: SPSSX(r) Discussion [mailto:SPSSX-L@LISTSERV.UGA.EDU]Em nome de
> Raynald Levesque
> Enviada em: quinta-feira, 4 de maio de 2000 21:33
> Para: SPSSX-L@LISTSERV.UGA.EDU
> Assunto: Re: Macro and data set variables
>
>
> Hi Guilherme!
>
> Yes, it is possible! Just about anything can be done in SPSS ;-)
>
> The following syntax (which I posted last year in this list) shows how to
> define a macro which is based on numbers calculated from the data file.
>
> In this case, one macro (named !sum_1) uses the sum of the values of cases
> where id=1
> The other macro (named !sum_tot) uses the total for all cases in the file.
>
> If this does not allow you to figure out a solution to your problem, do
not
> hesitate to provide more details on what you want to do and I will give it
> another crack.
>
> SET MPRINT=ON.
>
> DATA LIST LIST /id(F8) var1(F8).
> BEGIN DATA.
> 1 10
> 1 15
> 1 10
> 2 20
> 2 25
> 3 15
> 3 25
> END DATA.
> LIST.
>
> SAVE OUTFILE='data.sav'.
>
> COMPUTE break_v=(id=1).
> AGGREGATE
> /OUTFILE=*
> /BREAK=break_v
> /var1_1 = SUM(var1).
>
> DO IF break_v=1.
> WRITE OUTFILE 'temp.sps' /"DEFINE !sum_1()"/var1_1/"!ENDDEFINE.".
> ELSE.
> WRITE OUTFILE 'temp.sps' /"DEFINE !sum_tot()"/var1_1/"!ENDDEFINE.".
> END IF.
> EXE.
>
> INCLUDE 'temp.sps'.
> GET
> FILE='data.sav'.
>
> COMPUTE #a=!sum_1.
> COMPUTE #b=!sum_tot.
>
> DO IF id=1.
> COMPUTE var2 =#a.
> ELSE.
> COMPUTE var2 = #a/(#a + #b).
> END IF.
> FORMATS var2(F8.3).
> EXECUTE.
>
> HTH
>
> Raynald Levesque rlevesque@videotron.ca
>
>
>
>
> ----- Original Message -----
> From: Guilherme Coelho Rabello <gcoelho@INEP.GOV.BR>
> Newsgroups: bit.listserv.spssx-l
> To: <SPSSX-L@LISTSERV.UGA.EDU>
> Sent: Thursday, May 04, 2000 12:42 PM
> Subject: Macro and data set variables
>
>
> > Hi.
> >
> > Is it possible to put a variable value into a macro
> variable/statement ?
> > For example, I want to do something like this :
> >
> > .
> > .
> > .
> > !do !i=1 !to qtdtur.
> > .
> > .
> > .
> > !doend.
> > .
> > .
> > .
> > In this case, the qtdtur variable came from a working file.
thank
> you,
> >
> > Guilherme.
> >
> >
> > ------------------------------------------------------
> > Governo Federal/MEC/INEP
> > Diretoria de Avaliação da Educação Básica-DAEB
> > Coordenação Geral de Avaliação
> > Guilherme Coelho Rabello
> > Consultor UNDP
> > tel: +55 (61) 410-8424
> > e-mail : gcoelho@inep.gov.br
> > ------------------------------------------------------
>