| Date: | Wed, 14 Jun 2006 07:37:54 +0100 |
| Reply-To: | kornbrot <d.e.kornbrot@herts.ac.uk> |
| Sender: | "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU> |
| From: | kornbrot <d.e.kornbrot@herts.ac.uk> |
| Subject: | Re: Can't !LET & VAR LABELS be used in DO IF...ELSE IF... END IF
structures in MACROs? revisited |
|
| In-Reply-To: | <000901c68f1e$a6fbd2b0$6401a8c0@dwcv101> |
|---|
Yes better if 3 cars
diana
Professor Diana Kornbrot
University of Hertfordshire
College Lane, Hatfield, AL10 9AB, UK
Email: d.e.kornbrot@herts.ac.uk
Blended Learning Unit
voice: +44[0]170 728 4313 fax: +44[0] 170 728 4320
Psychology
voice: +44[0]170 728 4626 fax: +44[0]170 728 5073
Kornbrot
19 Elmhurst Avenue
London N2 0LT, UK
voice: +44[0208 883 3657 fax: +44[0] 0208 444 2081
> -----Original Message-----
> From: SPSSX(r) Discussion [mailto:SPSSX-L@LISTSERV.UGA.EDU]
> On Behalf Of David Wasserman
> Sent: 13 June 2006 20:22
> To: SPSSX-L@LISTSERV.UGA.EDU
> Subject: Re: Can't !LET & VAR LABELS be used in DO IF...ELSE
> IF... END IF structures in MACROs? revisited
>
> As I understand it, macros have three stages: definition,
> obviously, between DEFINE and !ENDDEFINE statements,
> expansion, and execution. Both expansion and execution take
> place when the macro is called, but are clearly a two-step
> process. When the macro you have presented expands,
> everything that is not a macro command, keyword, or argument
> is still just a string.
> During the expansion, the macro commands, keywords and
> arguments are resolved, and essentially disappear, replaced
> by the strings to which they resolve. The expansion happens
> only once, and while it is happening there are no variable
> values. Therefore, a DO IF structure, which depends on the
> existence of variable values, which change as often as there
> are cases, cannot control the execution of a !LET command.
> All the !LET commands expand before the resulting strings are
> treated as SPSS syntax. The end result is that the last !LET
> command used to assign a value to a macro keyword is the !LET
> command that gives that keyword the string content it has
> when the macro expanded output executes. Your example shows
> that: only the last !LET command appears to work.
>
> I hope that helps.
>
> David Wasserman
> Custom Data Analysis and SPSS Programming
>
> ----- Original Message -----
> From: "Marta García-Granero" <biostatistics@terra.es>
> Newsgroups: bit.listserv.spssx-l
> To: <SPSSX-L@LISTSERV.UGA.EDU>
> Sent: Tuesday, June 13, 2006 12:45 PM
> Subject: Can't !LET & VAR LABELS be used in DO IF...ELSE
> IF... END IF structures in MACROs? revisited
>
>
> > Hi everybody:
> >
> > Since my first post presented only part of a very long
> MACRO, perhaps
> > the problem can't be easily reproduced by other people.
> That's why I
> > have written a tiny demo that shows the problem:
> >
> > DATA LIST FREE/testvar.
> > BEGIN DATA
> > 1 1 1 2 2 2 3 3 3
> > END DATA.
> > FORMAT testvar (F8).
> >
> > DEFINE DEMOTEST(method=!TOKENS(1)).
> > DO IF !method EQ 1.
> > - VAR LABEL testvar 'Method #1 was selected'.
> > - !LET !label_1=!UNQUOTE('1-A').
> > - !LET !label_2=!UNQUOTE('1-B').
> > - !LET !label_3=!UNQUOTE('1-C').
> > ELSE IF !method EQ 2.
> > - VAR LABEL testvar 'Method #2 was selected'.
> > - !LET !label_1=!UNQUOTE('2-A').
> > - !LET !label_2=!UNQUOTE('2-B').
> > - !LET !label_3=!UNQUOTE('2-C').
> > ELSE.
> > - VAR LABEL testvar 'Other method was selected'.
> > - !LET !label_1=!UNQUOTE('Other-A').
> > - !LET !label_2=!UNQUOTE('Other-B').
> > - !LET !label_3=!UNQUOTE('Other-C').
> > END IF.
> > DO IF $casenum EQ 1.
> > - ECHO "The method used was:".
> > - ECHO !QUOTE(!method).
> > END IF.
> > VALUE LABEL testvar 1 !QUOTE(!QUOTE(!label_1))
> > 2 !QUOTE(!QUOTE(!label_2))
> > 3 !QUOTE(!QUOTE(!label_3)).
> > FREQUENCIES
> > VARIABLES=testvar.
> > !ENDDEFINE.
> >
> > DEMOTEST method=1.
> > DEMOTEST method=2.
> >
> > As you can see if you run this example, the last instance
> of the list
> > of DO IF... ELSE IF... ELSE is always selected.
> >
> > Can anybody enlighten me?
> >
> > Thanks,
> > Marta mailto:biostatistics@terra.es
> >
> > (Anyway: my Meta-analysis MACRO is written and working properly -
> > using a long workaround to the above mentioned problem -
> and available
> > on request).
> >
>
>
|