LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (November 2008, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 7 Nov 2008 12:06:31 -0600
Reply-To:     "./ ADD NAME=Data _null_," <iebupdte@GMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "./ ADD NAME=Data _null_," <iebupdte@GMAIL.COM>
Subject:      Re: how to pass this string to macro?
Comments: To: "Terjeson, Mark" <Mterjeson@russell.com>
In-Reply-To:  <16FD64291482A34F995D2AF14A5C932C044F557C@MAIL002.prod.ds.russell.com>
Content-Type: text/plain; charset=ISO-8859-1

Y'all can go on all you want about macro design, macro quoting and the like but you can pass commas without using a macro quoting function. As my original reply indicated. I think it would be more interesting to discuss a solution that does not involve the use of macros.

1341 %Macro calculateRFs(codetypecd=, id=, valueString=); 1342 %put _local_; 1343 proc sql; 1344 select * 1345 from a 1346 where a.str in &ValueString; 1347 quit; 1348 %mend calculateRFs; 1349 %calculateRFs(valueString=('111','222','3333'),codetypecd=1,id=1); CALCULATERFS VALUESTRING ('111','222','3333') CALCULATERFS ID 1 CALCULATERFS CODETYPECD 1

On 11/7/08, Terjeson, Mark <Mterjeson@russell.com> wrote: > Hi Toby, > > Glad you agree with all my points. :o) > Jeff might get the idea that we really > encourage not passing commas and not > using macro quoting unless absolutely > necessary. har har In these cases, > simplicity actually allows more complexity > and easier code reading (and writing). > > Mark > > > -----Original Message----- > From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of > Toby Dunn > Sent: Friday, November 07, 2008 9:16 AM > To: SAS-L@LISTSERV.UGA.EDU > Subject: Re: how to pass this string to macro? > > Why bother with quoting functins, the only reason they are needed is > because the macro was poorly designed to begin with (Ie. there are > commas > where there shouldnt be commas in the value being passed). Making a few > minor structural changes to the macro makes need for macro quoting to go > away all together. > > The number one rule of macro quoting is DONT unless you are absolutly > forced to do so. > > Toby Dunn > > On Fri, 7 Nov 2008 08:22:10 -0800, Terjeson, Mark > <Mterjeson@RUSSELL.COM> > wrote: > > >Hi Jeff, > > > >Here is one way. The SAS Macro facility > >has internal/invisible quoting characters > >that can encase your qoutes and commas: > > > > > > > >%Macro calculateRFs(codetypecd, id, valueString); > > > > proc sql; > > > > select * > > > > from sashelp.class as a > > > > where a.name in(%unquote(&valueString)); > > > >%mend calculateRFs; > > > >%calculateRFs(1, 1,%quote('James','Jane','Janet')); > > > > > > > >Something like this is pretty straightforward, > >but as many SAS-L sages and gurus may send along, > >is that there are other ways to re-arrange the > >code so that you do not have to use macro quoting, > >and to use macro quoting sparingly. Macro quoting > >can become unwieldy and troublesome if someone > >gets carried away. > > > > > >For example, you can build the string into a > >macro variable. If you pass the contents of the > >macro variable to the macro, then the quotes and > >commas will look like argument delimiters to the > >macro parser. However, if you pass just the macro > >variable name (and not the contents) then you > >forego the argument being passed from looking like > >commas and quotes. e.g. > > > > > >%let theNames='James','Jane','Janet'; > > > > > >%Macro calculateRFs(codetypecd, id, theMacroVarName); > > > > proc sql; > > > > select * > > > > from sashelp.class as a > > > > where a.name in(&&&theMacroVarName); > > > >%mend calculateRFs; > > > >%calculateRFs(1, 1,theNames); > > > > > > > >Voila, no commas and quotes or macro quoting > >functions to deal with. > > > > > >Of course, the %LET is when you have a static list. > >Your list can also be generated dynamically: e.g. > > > > > > > >proc sql noprint; > > select name into :theNames separated by '","' > > from sashelp.class > > where name eqt 'J'; > >quit; > > * trim and wrap outer quotes ; > >%let theNames="&theNames"; > >%put theNames is >&theNames<; > > > > > >%Macro calculateRFs(codetypecd, id, theMacroVarName); > > > > proc sql; > > > > select * > > > > from sashelp.class as a > > > > where a.name in(&&&theMacroVarName); > > > >%mend calculateRFs; > > > >%calculateRFs(1, 1,theNames); > > > > > > > > > > > > > >Hope this is helpful. > > > > > >Mark Terjeson > >Senior Programmer Analyst > >Investment Management & Research > >Russell Investments > >253-439-2367 > > > > > >Russell > >Global Leaders in Multi-Manager Investing > > > > > > > > > > > >-----Original Message----- > >From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of > >Jeff > >Sent: Friday, November 07, 2008 7:37 AM > >To: SAS-L@LISTSERV.UGA.EDU > >Subject: how to pass this string to macro? > > > >%Macro calculateRFs(codetypecd, id, valueString); > > > >proc sql; > > > >select * > > > >from a > > > >where a.str in &string; > > > >%mend calculateRFs; > >%calculateRFs(1, 1, ((*'111'*,*'222'*,*'3333'*));)); > > > >I want to pass string (*'111'*,*'222'*,*'3333') or > >**'111'*,*'222'*,*'3333' > >together as a stirng to the macro. How can I do that?* > >*Thanks.* > >*Jeff* >


Back to: Top of message | Previous page | Main SAS-L page