|Date: ||Tue, 14 Dec 2010 11:15:00 -0600|
|Reply-To: ||Warren Schlechte <Warren.Schlechte@TPWD.STATE.TX.US>|
|Sender: ||"SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>|
|From: ||Warren Schlechte <Warren.Schlechte@TPWD.STATE.TX.US>|
|Subject: ||Re: Creating Quoted Macro Variable for Text Comparison|
|Content-Type: ||text/plain; charset="us-ascii"|
Apparently I owe the list an apology for taking up their time.
As Mark and Chang note, the statement
If XVAR2="&xvar." then do...
Oddly, yesterday when I ran my code, I got an error at this section.
The error disappeared when I replaced the "&xvar." with "XVARNAME"
(removing the macro variable reference and using the actual literal
Today when I ran the same code, there is no error. Since I cannot
recreate the error, I'm left scratching my head.
From: Terjeson, Mark [mailto:Mterjeson@russell.com]
Sent: Tuesday, December 14, 2010 10:44 AM
To: Warren Schlechte; SAS-L@LISTSERV.UGA.EDU
Subject: RE: Creating Quoted Macro Variable for Text Comparison
You're syntax is correct. Any chance that if you
are getting an error or malfunction that it is
due to something else?
One likely possibility is the way the dataset B
gets constructed. For example if you run the
sample code below you will see that it is
successful. However, if you change applepie to
apple it will be unsuccessful. The XVAR2 variable
will be created with the length of the first
occurance which means that apple is a length of 5
and then when you run the sample code the match
will fail due to XVARNAME not equaling XVARN.
So you see your syntax can be correct but some
other influence tripping up the situation.
* sample data ;
XVARNAME=1; XVAR2='applepie'; output;
XVARNAME=1; XVAR2='XVARNAME'; output;
XVARNAME=1; XVAR2='banana'; output;
XVARNAME=2; XVAR2='misc'; output;
Where &xvar. = 1;
put / XVARNAME= XVAR2=;
If XVAR2="&xvar." then
put 'XVAR2 matched';
Hope this is helpful.
Investment Business Intelligence
Investment Management & Research
Global Leaders in Multi-Manager Investing
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
Sent: Tuesday, December 14, 2010 7:58 AM
Subject: Creating Quoted Macro Variable for Text Comparison
I what to be able to use a macro variable in open code as both regular
and quoted text, but try as I might, I cannot get it right. I can get
the literal part no problem, but not the quoted text. I have read some
of the macro-quoting functions papers, but have not yet been able to
figure out which one to use and how.
Here's what I want:
%let xvar= XVARNAME;
Where &xvar. =condition; /* Here it is used as a literal as in Where
XVARNAME = condition */
If XVAR2="&xvar." then do... /* Here I want it used "XVARNAME" as
quoted text */
I know this is simple (if you know what to do) so thanks for your help.
And happy holidays to all on this list.
HOH Fisheries Science Center
5103 Junction Hwy
Mt. Home, TX 78058
Phone 830.866.3356 x214