I'm trying to build into a macro which generates a macro defining a list of variables. I wish to loop over this list of variables using !EVAL(!list1) but !EVAL only picks up the evaluation of !list1 where !list1 was last assigned *outside* of the macro. Example and notes within macro below. I hope I have explained this clearly. Does anyone know a workaround to this?
DATA LIST LIST /v1 v2 v3 v4 v5. BEGIN DATA. 1.21 2.49 3.01 5.51 41.98 2.33 5.67 1.75 4.22 6.02 END DATA. *///////////////////////////////////////.
DEFINE !DefList (var1=!TOKENS(1) /var2=!TOKENS(1) /fname=!CMDEND) dataset name ds1.
dataset copy dsCopy. COMPUTE dummy=1.
N OF CASES 1. MATCH FILES FILE=* /BY dummy /KEEP=!var1 TO !var2. FLIP. COMPUTE dummy=1. MATCH FILES FILE=* /BY dummy /FIRST=first /LAST=last.
DO IF first. WRITE OUTFILE='c:\temp\list1.sps' / 'DEFINE !list1()' case_lbl. ELSE if not last. WRITE OUTFILE='c:\temp\list1.sps' / " "case_lbl. ELSE. WRITE OUTFILE='c:\temp\list1.sps' /" "case_lbl ' !ENDDEFINE'. END IF. EXECUTE. INCLUDE FILE='c:\temp\list1.sps'.
EXECUTE.
dataset close dsCopy.
dataset activate ds1. !do !i !in (!eval(!list1)) /* NOTE: here it does not pick up the !list1 which was assigned 3 lines above using INDLUDE FILE but instead picks up the last !list1 assigned outside of this macro*/
title !i. !doend descriptives vars=!list1. /* NOTE: here you can see it does pick up the correct !list from within this macro */
!ENDDEFINE.
*///////////////////////////////////////. set mprint on.
!DEfList var1=v1 var2=v5. !DEfList var1=v3 var2=v5. set mprint off.
Many thanks in advance
Jignesh
|
...I have seen this as a work around (http://www.spsstools.net/Syntax/WorkWithMissing/ListVariableNameWithMissingValuesAsWellAsIdentifyingElementsOfCase.txt)
but is it at all possible to achieve this without having 2 macros/2 macro calls? High preference would be to allow this to run in a single macro call for ease of use for the end user...
Crossing my fingers very tight....!
Many thanks
Jignesh
On 18 December 2010 15:24, J Sutar <[hidden email]> wrote:
|
I have build numerous macros recently and for almost for every macro I have to loop over a list of vars (e.g. !DO !i !in (!vars)) where !vars is an macro argument which takes a list of variables.
However, up until now, I have been entering this list of variables out but I'd like to be able to use the TO convention. Having come across this macro (see below) I thought it would be possible. It comes very close but fails at the last hurdle (for the reason I explained in my very first post).
I wonder if anyone could confirm whether it is possible achieve this or not...? It would be such a break through for me if it could be achieved...
Many thanks in advance
Jignesh
On 18 December 2010 17:12, J Sutar <[hidden email]> wrote:
|
Free forum by Nabble | Edit this page |