| 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 |
|
| In-Reply-To: | <16FD64291482A34F995D2AF14A5C932C09DA8100@MAIL002.prod.ds.russell.com> |
| 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...
works.
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
instead).
Today when I ran the same code, there is no error. Since I cannot
recreate the error, I'm left scratching my head.
Apologies,
Warren Schlechte
-----Original Message-----
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
Hi Warren,
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 ;
data B;
XVARNAME=1; XVAR2='applepie'; output;
XVARNAME=1; XVAR2='XVARNAME'; output;
XVARNAME=1; XVAR2='banana'; output;
XVARNAME=2; XVAR2='misc'; output;
run;
%let xvar=XVARNAME;
Data A;
Set B;
Where &xvar. = 1;
put / XVARNAME= XVAR2=;
If XVAR2="&xvar." then
do;
put 'XVAR2 matched';
end;
run;
Hope this is helpful.
Mark Terjeson
Investment Business Intelligence
Investment Management & Research
Russell Investments
206-505-2367
Russell
Global Leaders in Multi-Manager Investing
-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
Warren Schlechte
Sent: Tuesday, December 14, 2010 7:58 AM
To: SAS-L@LISTSERV.UGA.EDU
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;
Data A;
Set B;
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.
Warren Schlechte
HOH Fisheries Science Center
5103 Junction Hwy
Mt. Home, TX 78058
Phone 830.866.3356 x214
Fax 830.866.3549
|