Date: Mon, 11 Feb 2008 07:14:02 -0800
Reply-To: "Terjeson, Mark" <Mterjeson@RUSSELL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Terjeson, Mark" <Mterjeson@RUSSELL.COM>
Subject: Re: Change a coloumn name to a macro variable
In-Reply-To: A<3747e79c-32fa-46ba-a200-c01c557ee0af@j20g2000hsi.googlegroups.com>
Content-Type: text/plain; charset="us-ascii"
Hi,
Part of what you are wanting to do
is to concatenate fixed pieces of
string constants with a macro variable.
As you have shown, if you have PF&nDT
then the macro parser will be looking
for a macro variable name called &nDt
The SAS macro facility has a punctuation
syntax so that you can tell the parser
exactly where the spelling of the macro
variable stops and the next string constant
starts. It is the period. e.g.
PF&n.DT
i.e. when the macro parser comes up to
the period, and in many cases many other
punctuation characters, it will assume
that the letters denoting the macro
variable name end, thus above the parser
will treat the macro variable as &n
Please NOTE: other symbols will indeed
end the macro name BUT these symbols will
also be in your resulting string, however,
the period is a special marker for the
macro facility and when used as the ending
of a macro variable name, the period will
be gobbled up and thrown away. Therefore
%let n=8;
%put PF&n.DT;
will output as PF8DT
So, if you really do need a period, such
as in a filename or something, e.g.
%let myfilename=ABC;
%let thefilename=&myfilename..txt;
putting two dots will allow the macro
parser to gobble up the first one and
then leave the second period in your
resulting string.
Hope this is helpful.
Mark Terjeson
Senior Programmer Analyst, IM&R
Russell Investments
Russell Investments
Global Leaders in Multi-Manager Investing
-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
raisins
Sent: Monday, February 11, 2008 6:51 AM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Change a coloumn name to a macro variable
Hi,
I am stuck at changing a variable name to a macro variable:
ideally, I want to take N from my macro and append it to a string like
'PF'&n'DT'
I was able to get PF&nDT as a macro variable. ( In a very bad way,
better methods are welcome!)
%let myvar = PF&n ;
%let prefix = DT;
%put &myvar ;
%global newvar = &myvar&prefix ;
%put &newvar;
now I want to use it to rename a variable in Dataset,
i tried
data Subjsf (rename = (PFSnDT = symget('newvar')));
set Subjsf ;
run;
Thanks in advance!