Re: Help with macros
Posted by Eleonora Sidorova on
URL: http://spssx-discussion.165.s1.nabble.com/Help-with-macros-tp5740865p5740871.html
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.