Re: Help with macros

Posted by Bruce Weaver on
URL: http://spssx-discussion.165.s1.nabble.com/Help-with-macros-tp5740865p5740872.html

Hello Eleonora.  I'm still not at all sure I understand everything you want to do.  However, I think the key thing you are asking is how to assign to macro variable !@Nvars the number of variables in a list of variables.  If so, perhaps the following code will help you.  

* Count the number of variables in a list.
!LET !junk=""
!DO !var !IN (!List)
!LET !junk=!CONCAT(!junk,"x")
!DOEND
!LET !@Nvars = !LENGTH(!junk)

Good luck!
Bruce


Eleonora Sidorova wrote
In the first piece of data below, there are double codes that can turn out in the data.

In the second part, this is what I need after cleaning the double codes. Of course, for security, it is better when cleaning the codes inside the macro,

to transfer the codes to new variables, but then return them to the original ones. I will not overwrite the original data file, since it is in our

rules to work with a copy and I, in case of incorrect macro operation, can always restore the original data.



The number and name of variables for cleaning in each project is different.

Therefore, my idea was that we need to create a universal macro in which I would substitute variables that need to be cleaned,

and the macro would count everything else by itself. My snag now is that I do not know how to assign to !NVars the counted number of variables

in the range in order to first transfer them to new variables, without double ones, clean the original variables, and then return the data from the newly created variables to them.



data list list/HH (f2)Snack1 to Snack3 (3f2) Want1 to Want3 (3f2).

begin data

    01 97 96 3 1 2 3

    02 3 2 1 3 2 1

    03 98 99 2 1 3 2

    04 1 3 -1 1 3 -1

    05 1 -1 -1 1 -1 -1

    06 1 1 1 1 -2 -2

    07 1 2 2 1 2 -2

    08 1 2 1 1 2 -2

    09 98 99 99 98 96 97

end data.

*MISSING VALUES Snack1 to Want3 (LO THRU -1).

VALUE LABELS Snack1 to Want3

    1 'Apple'

    2 'Cherry'

    3 'Lemon'

    -3 'No response for any snack'

    -2 'duplicate of earlier response'

    -1 'fewer responses in Multiple Response'.





data list list/HH (f2)Snack1 to Snack3 (3f2) Want1 to Want3 (3f2).

begin data

    01 97 96 3 1 2

    02 3 2 1

    03 98 99 2 1 3

    04 1 3 -1

    05 1 -1

    06 1 -2

    07 1 2 -2

    08 1 2 -2

    09 98 99 96 97

end data.

*MISSING VALUES Snack1 to Want3 (LO THRU -1).

VALUE LABELS Snack1 to Want3

    1 'Apple'

    2 'Cherry'

    3 'Lemon'

    -3 'No response for any snack'

    -2 'duplicate of earlier response'

    -1 'fewer responses in Multiple Response'.



Thank you in advance for the answer.
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

PLEASE NOTE THE FOLLOWING: 
1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.
2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/).