f



How can I insert two macro variables name into one variable name

Hi

I have two macro variable, one is &ab the other is &cd. I want to insert
these two macro variables into one variable name like: flp&ab&cd.

But it seems this method does not work. Could you help me figure out what's
the format I should use?

Thank you very much

Jane
0
program.sas (104)
6/21/2007 2:07:45 PM
comp.soft-sys.sas 142827 articles. 4 followers. Post Follow

5 Replies
747 Views

Similar Articles

[PageSpeed] 35

Jane ,

Not sure where your problem is since you didnt provide any code nor log but
here is a couple of examples:

%Let AB = 123 ;
%Let CD = ABC ;
%Let FLP&AB&CD = FLP&AB&CD ;
%Put FLP&AB&CD = &&&FLP&AB&CD ;

Data _Null_ ;
FLP&AB&CD = "FLP&AB&CD" ;
Put FLP&AB&CD= ;
Run ;



Toby Dunn

If anything simply cannot go wrong, it will anyway.  Murphys Law #2.

The buddy system is essential to your survival; it gives the enemy somebody
else to shoot at.
Murphys Law #


Tell a man there are 300 billion stars in the universe and he'll believe
you. Tell him a bench has wet paint on it and he'll have to touch to be
sure.  Murphys Law #9






From: Jane <program.sas@GMAIL.COM>
Reply-To: Jane <program.sas@GMAIL.COM>
To: SAS-L@LISTSERV.UGA.EDU
Subject: How can I insert two macro variables name into one variable name
Date: Thu, 21 Jun 2007 10:07:45 -0400

Hi

I have two macro variable, one is &ab the other is &cd. I want to insert
these two macro variables into one variable name like: flp&ab&cd.

But it seems this method does not work. Could you help me figure out what's
the format I should use?

Thank you very much

Jane

_________________________________________________________________
Picture this � share your photos and you could win big!
http://www.GETREALPhotoContest.com?ocid=TXT_TAGHM&loc=us
0
tobydunn (6020)
6/21/2007 2:13:27 PM
Hi Jane,



%let ab=apple;
%let cd=cherry;
%let abcd=flp&ab&cd;

%put _global_;

If you are looking for a period in your text
then you need two of them.

%let abcd=flp&ab&cd..;
%put &abcd;

The reason is that you may have text following
the macro variable reference such as:

%let abcd=flp&abcherry;
%put &abcd;

This does not work because the computer cannot
distinguish "ab" from "abc" or "abch" or "abcherry",
so SAS uses a period to formally give you a way
to tell SAS where the macro name stops and the
text begins, such as:

%let abcd=flp&ab.cherry;
%put &abcd;

So the first period after a macro variable reference
essentially gets gobbled up.  Therefore if you really
want a period character at that same location you just
have to add a second one that will be left alone as
text since the first period gets gobbled up.

%let abcd=flp&ab..cherry;
%put &abcd;




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
Jane
Sent: Thursday, June 21, 2007 7:08 AM
To: SAS-L@LISTSERV.UGA.EDU
Subject: How can I insert two macro variables name into one variable
name

Hi

I have two macro variable, one is &ab the other is &cd. I want to insert
these two macro variables into one variable name like: flp&ab&cd.

But it seems this method does not work. Could you help me figure out
what's the format I should use?

Thank you very much

Jane
0
mterjeson (1913)
6/21/2007 2:19:14 PM
Thanks Toby and Mark

I found out why I can not simply insert two macro variables, since there two
macro variables were from two different macro procedures. I used them in
another macro procedure. It seemed I should define them as global macro
variables.

Do you think am I right?

Thanks
Jane

On 6/21/07, Terjeson, Mark <Mterjeson@russell.com> wrote:
>
> Hi Jane,
>
>
>
> %let ab=apple;
> %let cd=cherry;
> %let abcd=flp&ab&cd;
>
> %put _global_;
>
> If you are looking for a period in your text
> then you need two of them.
>
> %let abcd=flp&ab&cd..;
> %put &abcd;
>
> The reason is that you may have text following
> the macro variable reference such as:
>
> %let abcd=flp&abcherry;
> %put &abcd;
>
> This does not work because the computer cannot
> distinguish "ab" from "abc" or "abch" or "abcherry",
> so SAS uses a period to formally give you a way
> to tell SAS where the macro name stops and the
> text begins, such as:
>
> %let abcd=flp&ab.cherry;
> %put &abcd;
>
> So the first period after a macro variable reference
> essentially gets gobbled up.  Therefore if you really
> want a period character at that same location you just
> have to add a second one that will be left alone as
> text since the first period gets gobbled up.
>
> %let abcd=flp&ab..cherry;
> %put &abcd;
>
>
>
>
> 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
> Jane
> Sent: Thursday, June 21, 2007 7:08 AM
> To: SAS-L@LISTSERV.UGA.EDU
> Subject: How can I insert two macro variables name into one variable
> name
>
> Hi
>
> I have two macro variable, one is &ab the other is &cd. I want to insert
> these two macro variables into one variable name like: flp&ab&cd.
>
> But it seems this method does not work. Could you help me figure out
> what's the format I should use?
>
> Thank you very much
>
> Jane
>
0
program.sas (104)
6/21/2007 2:26:39 PM
Hi Jane,

If things are as you say, you are correct.
Macro variables created inside other macros
are not available outside of those macros.
Indeed they are local to those macros. Yes
if you make them global
    %global myvar;
in those macro routines, then the will be
available outside of those macros.

You can place the %GLOBAL statement
for them inside or outside of those routines.

e.g.



%macro xxx;
    %global aaa;
    %let aaa=hello;
    %put inside macro is &aaa;
%mend;
%xxx;
%put outside is &aaa;


%global bbb;
%macro yyy;
    %let bbb=hello;
    %put inside macro is &bbb;
%mend;
%yyy;
%put outside is &bbb;





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
Jane
Sent: Thursday, June 21, 2007 7:27 AM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Re: How can I insert two macro variables name into one variable
name

Thanks Toby and Mark

I found out why I can not simply insert two macro variables, since there
two macro variables were from two different macro procedures. I used
them in another macro procedure. It seemed I should define them as
global macro variables.

Do you think am I right?

Thanks
Jane

On 6/21/07, Terjeson, Mark <Mterjeson@russell.com> wrote:
>
> Hi Jane,
>
>
>
> %let ab=apple;
> %let cd=cherry;
> %let abcd=flp&ab&cd;
>
> %put _global_;
>
> If you are looking for a period in your text then you need two of
> them.
>
> %let abcd=flp&ab&cd..;
> %put &abcd;
>
> The reason is that you may have text following the macro variable
> reference such as:
>
> %let abcd=flp&abcherry;
> %put &abcd;
>
> This does not work because the computer cannot distinguish "ab" from
> "abc" or "abch" or "abcherry", so SAS uses a period to formally give
> you a way to tell SAS where the macro name stops and the text begins,
> such as:
>
> %let abcd=flp&ab.cherry;
> %put &abcd;
>
> So the first period after a macro variable reference essentially gets
> gobbled up.  Therefore if you really want a period character at that
> same location you just have to add a second one that will be left
> alone as text since the first period gets gobbled up.
>
> %let abcd=flp&ab..cherry;
> %put &abcd;
>
>
>
>
> 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
> Jane
> Sent: Thursday, June 21, 2007 7:08 AM
> To: SAS-L@LISTSERV.UGA.EDU
> Subject: How can I insert two macro variables name into one variable
> name
>
> Hi
>
> I have two macro variable, one is &ab the other is &cd. I want to
> insert these two macro variables into one variable name like:
flp&ab&cd.
>
> But it seems this method does not work. Could you help me figure out
> what's the format I should use?
>
> Thank you very much
>
> Jane
>
0
mterjeson (1913)
6/21/2007 2:41:15 PM
Thanks Mark

On 6/21/07, Terjeson, Mark <Mterjeson@russell.com> wrote:
>
> Hi Jane,
>
> If things are as you say, you are correct.
> Macro variables created inside other macros
> are not available outside of those macros.
> Indeed they are local to those macros. Yes
> if you make them global
>     %global myvar;
> in those macro routines, then the will be
> available outside of those macros.
>
> You can place the %GLOBAL statement
> for them inside or outside of those routines.
>
> e.g.
>
>
>
> %macro xxx;
>     %global aaa;
>     %let aaa=hello;
>     %put inside macro is &aaa;
> %mend;
> %xxx;
> %put outside is &aaa;
>
>
> %global bbb;
> %macro yyy;
>     %let bbb=hello;
>     %put inside macro is &bbb;
> %mend;
> %yyy;
> %put outside is &bbb;
>
>
>
>
>
> 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
> Jane
> Sent: Thursday, June 21, 2007 7:27 AM
> To: SAS-L@LISTSERV.UGA.EDU
> Subject: Re: How can I insert two macro variables name into one variable
> name
>
> Thanks Toby and Mark
>
> I found out why I can not simply insert two macro variables, since there
> two macro variables were from two different macro procedures. I used
> them in another macro procedure. It seemed I should define them as
> global macro variables.
>
> Do you think am I right?
>
> Thanks
> Jane
>
> On 6/21/07, Terjeson, Mark <Mterjeson@russell.com> wrote:
> >
> > Hi Jane,
> >
> >
> >
> > %let ab=apple;
> > %let cd=cherry;
> > %let abcd=flp&ab&cd;
> >
> > %put _global_;
> >
> > If you are looking for a period in your text then you need two of
> > them.
> >
> > %let abcd=flp&ab&cd..;
> > %put &abcd;
> >
> > The reason is that you may have text following the macro variable
> > reference such as:
> >
> > %let abcd=flp&abcherry;
> > %put &abcd;
> >
> > This does not work because the computer cannot distinguish "ab" from
> > "abc" or "abch" or "abcherry", so SAS uses a period to formally give
> > you a way to tell SAS where the macro name stops and the text begins,
> > such as:
> >
> > %let abcd=flp&ab.cherry;
> > %put &abcd;
> >
> > So the first period after a macro variable reference essentially gets
> > gobbled up.  Therefore if you really want a period character at that
> > same location you just have to add a second one that will be left
> > alone as text since the first period gets gobbled up.
> >
> > %let abcd=flp&ab..cherry;
> > %put &abcd;
> >
> >
> >
> >
> > 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
> > Jane
> > Sent: Thursday, June 21, 2007 7:08 AM
> > To: SAS-L@LISTSERV.UGA.EDU
> > Subject: How can I insert two macro variables name into one variable
> > name
> >
> > Hi
> >
> > I have two macro variable, one is &ab the other is &cd. I want to
> > insert these two macro variables into one variable name like:
> flp&ab&cd.
> >
> > But it seems this method does not work. Could you help me figure out
> > what's the format I should use?
> >
> > Thank you very much
> >
> > Jane
> >
>
0
program.sas (104)
6/21/2007 2:58:09 PM
Reply: