| Date: | Wed, 7 Jun 2006 17:30:53 +0000 |
| Reply-To: | iw1junk@COMCAST.NET |
| Sender: | "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU> |
| From: | Ian Whitlock <iw1junk@COMCAST.NET> |
| Subject: | Re: Using macro Variables |
|
Ed,
You have raised some questions that I think are worth looking at and
understanding.
First of all, I didn't see what I would call an adequate response to
your original question. So let me explain. You concatenate by
juxtaposition. However, there is a problem when adding text to the
reference to a macro variable. For example, what should
&lib1
mean? Should it be the reference &LIB followed by a 1, hence COTTON1? Or
should it be the reference to an undefined macro variable, LIB1? Clearly,
both interpretations may be needed at one time or another. Hence there
must be a symbol to indicate the end of variable name. The macro facility
uses a dot to be this ender. Hence, &LIB1, is the reference to the
undefined LIB1, and &LIB.1 is an expression standing for COTTON1. Note the
dot is eaten by the macro facility because it is part of the instruction
for evaluating the expression, it is not part of the value. Now look at
&LIB..1. The first dot ends the expression, so what is the second dot? It
must be part of the value. Hence the expression stands for COTTON.1.
Now let's look at the deeper questions you raise about proper SAS-L
behavior. Is it reasonable to ask this question on SAS-L? Most definitely
yes? For one, the answer above shows that a lot is going on here and it is
easy for someone not familiar with the macro facility to need help in
understanding how and why the answer works. So I agree with Ed Heaton.
On the other hand, you should also appreciate the view of Lou and Toby.
Consider an analogy. A man walks into a gun shop and wants to buy a
machine gun. He then asks what is the function of this little thingy
(called a trigger). What is the problem? Well one might think it is
rather dangerous to sell the man such a killing machine when he has just
demonstrated such a lack of knowledge about what he is getting? In the US,
the law settles the question, if the man cannot be shown to be a criminal,
he must be sold the gun and it is the public's problem how to handle any
miss use. The macro facility, is something like a machine gun, not for use
in untrained hands.
So your question is a legitimate one, but it also makes one wonder whether
you have credentials for using the macro facility. Hence Toby and Lou also
have a point.
The fact that your code:
>> *** Declare Macro Variables Here
*******************************************;
>> %let lib = Cotton;
>> %let lib_path = C:\Rachel Badger\;
>> %let in_xl_file = CYT105v1;
>> %let in_xl_sheet = CYT105v1;
>> %let in_xl_range = CYT105v1;
>> %let excel_version = excel2000;
>> %let array_columns = Fiftywt lintwt seedwt yield12 MIC UHM UI STR ELO
SFC;
>>
***************************************************************************
;
looks very professional, really highlights the disconnect between the place
of the question and what an appropriate answer is.
Finally I note that Chris' answer (or Art's),
> [...] For example:
>
>filename excel "&lib_path&in_xl_file..csv";
>
leaves some important things out. For one, it would have been better to
make the assignment
%let lib_path = C:\Rachel Badger;
so that the reference
filename excel "&lib_path\&in_xl_file..csv";
is more readable. Now we are brought to the significant usage of the
double quotes. The macro facility doesn't resolve macro expressions inside
single quotes. When working with EXCEL there will probably be times that
single quotes are required, hence you may want to ask how to handle this
problem. I hope that you will do so, and that you will find sufficient
respect for your question. On the other hand, using the SAS-L search
facility at http://lexjansen.com/sugi/ with words "single quote" and author
"whitlock", using sorted by date, got some previous answers to this problem.
Your lesson, keep asking questions, is a good one for everybody.
Ian Whitlock
==================
Date: Mon, 5 Jun 2006 12:52:03 -0400
Reply-To: Edzard van Santen <evsanten@ACESAG.AUBURN.EDU>
Sender: "SAS(r) Discussion"
From: Edzard van Santen <evsanten@ACESAG.AUBURN.EDU>
Subject: Re: Using macro Variables
Thanks for the quick response to my question. Working in an educational
setting I have one criticism of the responses I received. First, however,
let me point out that all respondents pointed me in the right direction.
But
two-thirds of the respondents chided me for asking such as simple question
in the first place when I could have found the answer in the documentation.
I am trying desperately to teach my students that there is no stupid
question and as long as they ask questions they will learn.
SO, all you wizards of SAS and folks who make their living using SAS, have
mercy on the rest of us who are trying to learn by asking simple questions.
Not all problems are earth shattering.
On Mon, 5 Jun 2006 07:47:27 -0700, chris@OVIEW.CO.UK wrote:
>Hi,
>
>You really need to read the (online) documentation about the macro
>language - this is the sort of thing you would learn in the first ten
>minutes of a SAS Macro course.
>
>Anyway, to answer your question - prefixing the name of a macro
>variable with an ampersand will cause the macro processor to subtitute
>the variable's value. When doing this in a quoted string, use double
>quotes, not single. For example:
>
>filename excel "&lib_path&in_xl_file..csv";
>
>The two full stops (periods) are intentional - you'll learn why when
>(if?) you read the docs.
>
>Chris.
>--------------------------------------------------------
>Elvis SAS Log Analyser - http://www.oview.co.uk/elvis
>--------------------------------------------------------
>
>Edzard van Santen wrote:
>> Suppose I am decalring the following macro variables at the start of my
program
>> *** Declare Macro Variables Here
*******************************************;
>> %let lib = Cotton;
>> %let lib_path = C:\Rachel Badger\;
>> %let in_xl_file = CYT105v1;
>> %let in_xl_sheet = CYT105v1;
>> %let in_xl_range = CYT105v1;
>> %let excel_version = excel2000;
>> %let array_columns = Fiftywt lintwt seedwt yield12 MIC UHM UI STR ELO
SFC;
>>
***************************************************************************
;
>> How do I concatenate these variables to create the names for
>>
>> The EXCEL file to be imported C:\Rachel Badger\CYT105v1.xls
>>
>> the final SAS datset Cotton.CYT105v1
>>
>> ?
|