f

#### Re: &&&&&& #12

```Talbot,

From another message you already seem satisfied with the
thoughts for they give a different point of view.  The basic
question might be interpreted as, "Why does it take so many
ampersands to express 'daisy=yellow'?"  The implied question
might be what is wrong with my structure and how should it be
fixed?  I am interested in both.

A macro variable can be thought of as a name pointing at a value.
So a name can point at a name that can point at a value, etc.
Let's look at the problem by analogy.  Suppose you go to a party
and they decide to play the pointing game.  The question arises
how many people (including Bill) does it take for John to point
at Bill.  You might think just John and Bill.  But I haven't told
you all rules yet.  Here are the rules

A man can only point at his wife.
A wife can only point at a daughter.
A daughter can only point at a brother.
Bill is not the son of John.

Now the question may not even have an answer.  If it does then at
least 7 people are needed to start with John and end up pointing
at Bill.  Why so many?  Because the rules add a structure that
restricts pointing, i.e. who can point at whom.  You should be
able to show that if the number 7 is realized at this party, then
Bill is a grandson of John.

So the lesson here is that adding structure to pointing can make
it necessary to add more people to a chain of pointers.  Why does
one add structure to the pointers?  Because some problems have a
natural structure and the code is easier when it reflects that
structure.

Now let's look at the structure you have.

MLV names an array of macro variables.  Any one variable in
this array is given by the indexing macro variable MLIN. That
macro variable, say MVL5 points at the macro variable DAISY,
which in turn points at YELLOW.  Symbolically

MLIN(5) --> MVL5 --> DAISY --> YELLOW

The formula for the number of ampersands is

2**n - 1

where N is the number of "-->"

In your case N=3 so 7 ampersands are needed to express

DAISY = YELLOW

in terms of MLIN.  Note that one number, 5, expressed as one
variable MLIN determines the whole line in terms of constant
text, MLV, and ampersands. Thus you might intuit that many
ampersands will be needed to do the work. If there are no
restrictions then

&X = &Y

would do when X and Y are defined correctly.  Why is it required
to use one piece of constant text MLV?  You should also realize
that using two arrays will make the job easier.  Consider:

&&X&I = &&Y&I

where I is the index and X and Y are the names of the arrays.  I
suspect that your failure to introduce the second array is what
forced the messiness of your expressions.  Essentially, I stored
the information DAISY and YELLOW in macro variables rather than
storing DAISY in the name of a macro variable.

From another point of view, your code intertwines two structures:

1) An array of macro variables whose values come from a column
of data

2) A set of macro variable names and the corresponding values
defined by two corresponding columns of data

Either structure alone is valuable.  Arrays are too common and
have too many different uses to list here.  (The use of arrays
has been declining since SQL made it easy to store a list of
values in one variable, but it will never completely go away.)
The second structure is handy when one wishes to capture the
state of available macro variables at some point in macro and
then restart the macro from that point in another session.
Another use might be when one has a macro with many parameters
and wants to store several coordinated default settings in files.

I cannot imagine a problem that would require both structures at
once unless variable names are being used to store information
rather than variable values.  Either you need to loop through a
list of values and an array is appropriate, or you need specific
variable names for lots of variables in which case it might be
appropriate to define them using the second structure.

Ian Whitlock
===================
Date:         Thu, 9 Jun 2005 13:38:44 -0400
Sender:       "SAS(r) Discussion"
From:         Talbot Michael Katz <topkatz@MSN.COM>
Subject:      &&&&&&
Hi.
It requires SIX ampersands to resolve the macro variable example
below:
data _null_ ;
set DS1 end = last ;
call symput("mlv" || compress(put(_N_,best32.)), mli)
;
call symput(mli, tdt) ;
if last then do ;
call symput("mlin", compress(put(_N_,best32.))) ;
end ;
run ;
%put &&mlv&mlin.  = &&&&&&mlv&mlin. ;
(So, if there are five observations in the data set, and the
fifth value of
mli is "DAISY" and the fifth value of tdt is "YELLOW" this will
print
out "DAISY = YELLOW")
Why does it take so many ampersands to resolve?  Can someone
this resolution to me so that it gets through my extremely dense
skull?
Thanks!

--  TMK  --
"The Macro Klutz"
```
 0
iw1junk (1187)
6/11/2005 5:07:55 PM
comp.soft-sys.sas 142828 articles. 3 followers.

0 Replies
1176 Views

Similar Articles

[PageSpeed] 48