<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Passing two parameters with bquote data null in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Passing-two-parameters-with-bquote-data-null/m-p/622944#M183291</link>
    <description>&lt;P&gt;If you find that you frequently need to macro quote the arguments to your macro you might find it easier to pass the values with actual quotes. Especially if you are passing the values with SAS code where you could use the QUOTE() function to add the quotes.&lt;/P&gt;
&lt;P&gt;Just make your macro smart enough to remove the quotes. Assuming you actually need to remove them, since most values that would require elaborate quoting to be used a macro call are probably going to be used by the macro to generate SAS code where you would just have to add the quotes back anyway.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is an example where the macro can pull off the quotes (if there) and then add them back when needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro mymacro(parm1,parm2);
%local q1 q2 ;
%let parm1=%qsysfunc(dequote(&amp;amp;parm1));
%let parm2=%qsysfunc(dequote(&amp;amp;parm2));
%let q1=%sysfunc(quote(&amp;amp;parm1,%str(%')));
%let q2=%sysfunc(quote(&amp;amp;parm2,%str(%')));

%put &amp;amp;=parm1 &amp;amp;=parm2;
%put &amp;amp;=q1 &amp;amp;=q2;

data _null_;
  put 'parm1=' &amp;amp;q1 ;
  put 'parm2=' &amp;amp;q2 ;
  put "Both = &amp;amp;parm1 &amp;amp;parm2" ;
run;
%mend mymacro;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Example calls:&lt;/P&gt;
&lt;PRE&gt;73    options mprint;
74    %mymacro(parm1=Hi there,parm2='Has a,comma');
PARM1=Hi there PARM2=Has a,comma
Q1='Hi there' Q2='Has a,comma'
MPRINT(MYMACRO):   data _null_;
MPRINT(MYMACRO):   put 'parm1=' 'Hi there' ;
MPRINT(MYMACRO):   put 'parm2=' 'Has a,comma' ;
MPRINT(MYMACRO):   put "Both = Hi there Has a,comma" ;
MPRINT(MYMACRO):   run;

parm1=Hi there
parm2=Has a,comma
Both = Hi there Has a,comma
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


75    %mymacro(parm1='Hi there',parm2=%bquote(Has a,comma));
PARM1=Hi there PARM2=Has a,comma
Q1='Hi there' Q2='Has a,comma'
MPRINT(MYMACRO):   data _null_;
MPRINT(MYMACRO):   put 'parm1=' 'Hi there' ;
MPRINT(MYMACRO):   put 'parm2=' 'Has a,comma' ;
MPRINT(MYMACRO):   put "Both = Hi there Has a,comma" ;
MPRINT(MYMACRO):   run;

parm1=Hi there
parm2=Has a,comma
Both = Hi there Has a,comma
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


76    %mymacro(parm1="Hi there",parm2=%bquote(Hasn't a comma));
PARM1=Hi there PARM2=Hasn't a comma
Q1='Hi there' Q2='Hasn''t a comma'
MPRINT(MYMACRO):   data _null_;
MPRINT(MYMACRO):   put 'parm1=' 'Hi there' ;
MPRINT(MYMACRO):   put 'parm2=' 'Hasn''t a comma' ;
MPRINT(MYMACRO):   put "Both = Hi there Hasn't a comma" ;
MPRINT(MYMACRO):   run;

parm1=Hi there
parm2=Hasn't a comma
Both = Hi there Hasn't a comma
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds&lt;/PRE&gt;</description>
    <pubDate>Fri, 07 Feb 2020 05:39:29 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2020-02-07T05:39:29Z</dc:date>
    <item>
      <title>Passing two parameters with bquote data null</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Passing-two-parameters-with-bquote-data-null/m-p/622872#M183250</link>
      <description>&lt;P&gt;What do I need to add here so that this line works?&lt;/P&gt;
&lt;P&gt;put '%allProgForAcadDisplayInter(%bquote(' SMRPRLE_PROGRAM +(-1), SMRPRLE_PROGRAM_DESC +(-1) '))';&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%global curProgram curProgramDesc;

%macro allProgForAcadDisplayInter(curProgram, curProgramDesc);
	%let curProgram = &amp;amp;curProgram;
	%put curProgram &amp;amp;curProgram;
	%put curProgramDesc &amp;amp;curProgramDesc; 
%mend;

%macro DisplayDemo();
	proc sql;
		create table AllProgramList (
			SMRPRLE_PROGRAM varchar(100),
			SMRPRLE_PROGRAM_DESC varchar(100)
		);

		insert into AllProgramList(SMRPRLE_PROGRAM, SMRPRLE_PROGRAM_DESC) values ("One", "Apple");
		insert into AllProgramList(SMRPRLE_PROGRAM, SMRPRLE_PROGRAM_DESC) values ("Two", "Orange");
	quit;

	filename code temp;
	data _null_; set AllProgramList;                                                                                                                     
	  	file code;
		
		put '%allProgForAcadDisplayInter(%bquote(' SMRPRLE_PROGRAM +(-1) '))';  
		put '%allProgForAcadDisplayInter(%bquote(' SMRPRLE_PROGRAM +(-1), SMRPRLE_PROGRAM_DESC +(-1) '))';  /*how can I make this line work*/
		
	run;  
	%include code / source2;
%mend;

%DisplayDemo();
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Feb 2020 21:12:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Passing-two-parameters-with-bquote-data-null/m-p/622872#M183250</guid>
      <dc:creator>DavidPhillips2</dc:creator>
      <dc:date>2020-02-06T21:12:44Z</dc:date>
    </item>
    <item>
      <title>Re: Passing two parameters with bquote data null</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Passing-two-parameters-with-bquote-data-null/m-p/622879#M183252</link>
      <description>&lt;P&gt;Found it&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;put '%allProgForAcadDisplayInter(%bquote(' SMRPRLE_PROGRAM +(-1) '),  %bquote(' SMRPRLE_PROGRAM_DESC +(-1) '))';&lt;/PRE&gt;</description>
      <pubDate>Thu, 06 Feb 2020 21:31:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Passing-two-parameters-with-bquote-data-null/m-p/622879#M183252</guid>
      <dc:creator>DavidPhillips2</dc:creator>
      <dc:date>2020-02-06T21:31:10Z</dc:date>
    </item>
    <item>
      <title>Re: Passing two parameters with bquote data null</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Passing-two-parameters-with-bquote-data-null/m-p/622880#M183253</link>
      <description>&lt;P&gt;That depends on what it is supposed to do.&amp;nbsp; My guessing skills lead me to believe that a change is required in the middle where this appears:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;+(-1),&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I imagine you want the comma to become part of the CODE file, and thus would need:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;+(-1) ","&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Ah, even better that you found the solution yourself!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Feb 2020 21:33:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Passing-two-parameters-with-bquote-data-null/m-p/622880#M183253</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2020-02-06T21:33:21Z</dc:date>
    </item>
    <item>
      <title>Re: Passing two parameters with bquote data null</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Passing-two-parameters-with-bquote-data-null/m-p/622944#M183291</link>
      <description>&lt;P&gt;If you find that you frequently need to macro quote the arguments to your macro you might find it easier to pass the values with actual quotes. Especially if you are passing the values with SAS code where you could use the QUOTE() function to add the quotes.&lt;/P&gt;
&lt;P&gt;Just make your macro smart enough to remove the quotes. Assuming you actually need to remove them, since most values that would require elaborate quoting to be used a macro call are probably going to be used by the macro to generate SAS code where you would just have to add the quotes back anyway.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is an example where the macro can pull off the quotes (if there) and then add them back when needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro mymacro(parm1,parm2);
%local q1 q2 ;
%let parm1=%qsysfunc(dequote(&amp;amp;parm1));
%let parm2=%qsysfunc(dequote(&amp;amp;parm2));
%let q1=%sysfunc(quote(&amp;amp;parm1,%str(%')));
%let q2=%sysfunc(quote(&amp;amp;parm2,%str(%')));

%put &amp;amp;=parm1 &amp;amp;=parm2;
%put &amp;amp;=q1 &amp;amp;=q2;

data _null_;
  put 'parm1=' &amp;amp;q1 ;
  put 'parm2=' &amp;amp;q2 ;
  put "Both = &amp;amp;parm1 &amp;amp;parm2" ;
run;
%mend mymacro;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Example calls:&lt;/P&gt;
&lt;PRE&gt;73    options mprint;
74    %mymacro(parm1=Hi there,parm2='Has a,comma');
PARM1=Hi there PARM2=Has a,comma
Q1='Hi there' Q2='Has a,comma'
MPRINT(MYMACRO):   data _null_;
MPRINT(MYMACRO):   put 'parm1=' 'Hi there' ;
MPRINT(MYMACRO):   put 'parm2=' 'Has a,comma' ;
MPRINT(MYMACRO):   put "Both = Hi there Has a,comma" ;
MPRINT(MYMACRO):   run;

parm1=Hi there
parm2=Has a,comma
Both = Hi there Has a,comma
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


75    %mymacro(parm1='Hi there',parm2=%bquote(Has a,comma));
PARM1=Hi there PARM2=Has a,comma
Q1='Hi there' Q2='Has a,comma'
MPRINT(MYMACRO):   data _null_;
MPRINT(MYMACRO):   put 'parm1=' 'Hi there' ;
MPRINT(MYMACRO):   put 'parm2=' 'Has a,comma' ;
MPRINT(MYMACRO):   put "Both = Hi there Has a,comma" ;
MPRINT(MYMACRO):   run;

parm1=Hi there
parm2=Has a,comma
Both = Hi there Has a,comma
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


76    %mymacro(parm1="Hi there",parm2=%bquote(Hasn't a comma));
PARM1=Hi there PARM2=Hasn't a comma
Q1='Hi there' Q2='Hasn''t a comma'
MPRINT(MYMACRO):   data _null_;
MPRINT(MYMACRO):   put 'parm1=' 'Hi there' ;
MPRINT(MYMACRO):   put 'parm2=' 'Hasn''t a comma' ;
MPRINT(MYMACRO):   put "Both = Hi there Hasn't a comma" ;
MPRINT(MYMACRO):   run;

parm1=Hi there
parm2=Hasn't a comma
Both = Hi there Hasn't a comma
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds&lt;/PRE&gt;</description>
      <pubDate>Fri, 07 Feb 2020 05:39:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Passing-two-parameters-with-bquote-data-null/m-p/622944#M183291</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-02-07T05:39:29Z</dc:date>
    </item>
  </channel>
</rss>

