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
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
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
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 >
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 >
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 > > >