<?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: Getting an error when using a macro with paramaters with single quotes in CALL EXECUTE in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Getting-an-error-when-using-a-macro-with-paramaters-with-single/m-p/547718#M151806</link>
    <description>&lt;P&gt;Okay, let's start with the absolute basic fundamentals here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You write a macro called %TEST, but then in CALL EXECUTE you are trying to run a macro called %DEDUCTIBLE.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Could this be the problem?&lt;/P&gt;</description>
    <pubDate>Mon, 01 Apr 2019 20:05:26 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2019-04-01T20:05:26Z</dc:date>
    <item>
      <title>Getting an error when using a macro with paramaters with single quotes in CALL EXECUTE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-an-error-when-using-a-macro-with-paramaters-with-single/m-p/547712#M151802</link>
      <description>&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;Hello, I am trying to use a macro within CALL EXECUTE. The source data for the macro is a data set with two fields: Group and Employer. Group never has any special characters, but Employer may have an apostrophe. When I run the following code, I get the following error:&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR: Expected close parenthesis after macro function invocation not found.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;This is a simplified version of my macro:&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test (Group,Employer); 
proc sql; 
create table test as
select distinct
	MemberID
	,"&amp;amp;Employer" as Employer
	,"&amp;amp;Group" as Group
from Membership
where EmployerID like "&amp;amp;Group%" 
	and Date between "01Jan2017"d and "31Dec2017"d 
;quit; 
%mend; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;This is the CALL EXECUTE code:&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
	set work.list;
	call execute('%nrstr(%deductible(
		 '||strip(Group)||'
		,'||strip(Employer)||'
	);)');
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;As long as there are no special characters in&amp;nbsp;the Employer field, my code runs without problem. The macro runs without problem, even with apostrophes,&amp;nbsp;with:&amp;nbsp;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%test (123456,%bquote(O'Test Employer));&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;So I tried to&amp;nbsp;use: &lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
	set work.list;
	call execute('%nrstr(%deductible(
		 '||strip(Group)||'
		,%bquote('||strip(Employer)||')
	);)');
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;How can I get SAS to ignore&amp;nbsp;any&amp;nbsp;apostrophes that my come up in the Employer&amp;nbsp;field? Any help is appreciated, thank you!&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Apr 2019 19:42:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-an-error-when-using-a-macro-with-paramaters-with-single/m-p/547712#M151802</guid>
      <dc:creator>rhachey</dc:creator>
      <dc:date>2019-04-01T19:42:54Z</dc:date>
    </item>
    <item>
      <title>Re: Getting an error when using a macro with paramaters with single quotes in CALL EXECUTE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-an-error-when-using-a-macro-with-paramaters-with-single/m-p/547715#M151803</link>
      <description>&lt;P&gt;Have you tried %NRBQUOTE instead %BQUOTE ?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Apr 2019 19:56:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-an-error-when-using-a-macro-with-paramaters-with-single/m-p/547715#M151803</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2019-04-01T19:56:35Z</dc:date>
    </item>
    <item>
      <title>Re: Getting an error when using a macro with paramaters with single quotes in CALL EXECUTE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-an-error-when-using-a-macro-with-paramaters-with-single/m-p/547716#M151804</link>
      <description>&lt;P&gt;Yes, and I still get the same error.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Apr 2019 20:01:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-an-error-when-using-a-macro-with-paramaters-with-single/m-p/547716#M151804</guid>
      <dc:creator>rhachey</dc:creator>
      <dc:date>2019-04-01T20:01:31Z</dc:date>
    </item>
    <item>
      <title>Re: Getting an error when using a macro with paramaters with single quotes in CALL EXECUTE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-an-error-when-using-a-macro-with-paramaters-with-single/m-p/547718#M151806</link>
      <description>&lt;P&gt;Okay, let's start with the absolute basic fundamentals here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You write a macro called %TEST, but then in CALL EXECUTE you are trying to run a macro called %DEDUCTIBLE.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Could this be the problem?&lt;/P&gt;</description>
      <pubDate>Mon, 01 Apr 2019 20:05:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-an-error-when-using-a-macro-with-paramaters-with-single/m-p/547718#M151806</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-04-01T20:05:26Z</dc:date>
    </item>
    <item>
      <title>Re: Getting an error when using a macro with paramaters with single quotes in CALL EXECUTE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-an-error-when-using-a-macro-with-paramaters-with-single/m-p/547720#M151808</link>
      <description>&lt;P&gt;One easy way is to allow your macro to accept actual quotes.&lt;/P&gt;
&lt;P&gt;For example this macro will except values with or without quotes around them.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test (Group,Employer);
%let group=%sysfunc(quote(%qsysfunc(dequote(%superq(group))),%str(%')));
%let employer=%sysfunc(quote(%qsysfunc(dequote(%superq(employer))),%str(%')));
proc sql;
create table test as
select distinct
   MemberID
  ,&amp;amp;Employer as Employer length=20
  ,&amp;amp;Group as Group length=20
from Membership
where EmployerID like &amp;amp;Group||'%'
  and Date between "01Jan2017"d and "31Dec2017"d
;
quit;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then call the macro with quoted values.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set work.list;
  call execute(cats('%nrstr(%deductible)'
,'(',quote(trim(group),"'")
,',',quote(trim(employer),"'")
,')'
));
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 01 Apr 2019 20:06:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-an-error-when-using-a-macro-with-paramaters-with-single/m-p/547720#M151808</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-04-01T20:06:48Z</dc:date>
    </item>
    <item>
      <title>Re: Getting an error when using a macro with paramaters with single quotes in CALL EXECUTE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-an-error-when-using-a-macro-with-paramaters-with-single/m-p/547723#M151810</link>
      <description>&lt;P&gt;Next thought&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instead of %NRBQUOTE or %BQUOTE, I think you really want %NRSTR to handle apostrophe's and other special characters. If it is a single apostrophe, rather then a pair, you might have to precede it with % as stated here:&amp;nbsp;&lt;A href="https://documentation.sas.com/?cdcId=pgmmvacdc&amp;amp;cdcVersion=9.4&amp;amp;docsetId=mcrolref&amp;amp;docsetTarget=n09tblrxldh8k0n1kt6dkj3xlxug.htm&amp;amp;locale=en"&gt;https://documentation.sas.com/?cdcId=pgmmvacdc&amp;amp;cdcVersion=9.4&amp;amp;docsetId=mcrolref&amp;amp;docsetTarget=n09tblrxldh8k0n1kt6dkj3xlxug.htm&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Apr 2019 20:09:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-an-error-when-using-a-macro-with-paramaters-with-single/m-p/547723#M151810</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-04-01T20:09:37Z</dc:date>
    </item>
    <item>
      <title>Re: Getting an error when using a macro with paramaters with single quotes in CALL EXECUTE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-an-error-when-using-a-macro-with-paramaters-with-single/m-p/547724#M151811</link>
      <description>&lt;P&gt;You can avoid a lot of the timing issues with CALL EXECUTE by just writing to a file and using %INCLUDE instead.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename code temp;
data _null_;
  set work.list;
  file code ;
  put '%deductible(%bquote(' group +(-1) '),%bquote(' employer +(-1) '));';
run;
%include code / source2;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 01 Apr 2019 20:11:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-an-error-when-using-a-macro-with-paramaters-with-single/m-p/547724#M151811</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-04-01T20:11:56Z</dc:date>
    </item>
    <item>
      <title>Re: Getting an error when using a macro with paramaters with single quotes in CALL EXECUTE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-an-error-when-using-a-macro-with-paramaters-with-single/m-p/547726#M151812</link>
      <description>&lt;P&gt;A simple workaround would be to write the macro calls to a file instead of using CALL EXECUTE:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
file mcalls temp;

data _null_;
  set list;
  file mcalls;
  put '%deductible(' strip(Group) ',' strip(Employer) ')';
run;

%include mcalls;
  &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that the final semicolon is not necessary when calling a macro, and occasionally can harm the program's logic.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the STRIP function causes problems, you should be able to just remove it:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;put '%deductible(' group ',' employer ')';&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the single quotes cause problems, you can add %bquote back in:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;put '%deductible(' group ', %bquote(' employer '))';&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Apr 2019 20:18:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-an-error-when-using-a-macro-with-paramaters-with-single/m-p/547726#M151812</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-04-01T20:18:40Z</dc:date>
    </item>
    <item>
      <title>Re: Getting an error when using a macro with paramaters with single quotes in CALL EXECUTE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-an-error-when-using-a-macro-with-paramaters-with-single/m-p/548553#M152110</link>
      <description>&lt;P&gt;Sorry, in trying to simplify my code to post here, I forgot to change the %DEDUCTIBLE to %TEST in my post.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Apr 2019 16:34:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-an-error-when-using-a-macro-with-paramaters-with-single/m-p/548553#M152110</guid>
      <dc:creator>rhachey</dc:creator>
      <dc:date>2019-04-04T16:34:49Z</dc:date>
    </item>
    <item>
      <title>Re: Getting an error when using a macro with paramaters with single quotes in CALL EXECUTE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-an-error-when-using-a-macro-with-paramaters-with-single/m-p/548560#M152115</link>
      <description>&lt;P&gt;Thank you, this works! But I don't understand how/why... can you explain the code a bit, or point me in the direction of resources? Especially the +(-1) piece. Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 04 Apr 2019 16:56:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-an-error-when-using-a-macro-with-paramaters-with-single/m-p/548560#M152115</guid>
      <dc:creator>rhachey</dc:creator>
      <dc:date>2019-04-04T16:56:29Z</dc:date>
    </item>
    <item>
      <title>Re: Getting an error when using a macro with paramaters with single quotes in CALL EXECUTE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-an-error-when-using-a-macro-with-paramaters-with-single/m-p/548581#M152128</link>
      <description>&lt;P&gt;The FILENAME statement will create a fileref to use for a temporary file.&lt;/P&gt;
&lt;P&gt;The data step then writes to the file.&lt;/P&gt;
&lt;P&gt;The %INCLUDE statement will execute the code in the file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The data step reads the data and writes one line per observation using a simple PUT statement. The quoted text is written as is. The variable names reference variables in the input dataset. The pointer motion command removes the extra space that PUT adds when you write a variable in list mode (without a format specification). It does this by moving the pointer back one space so that the next thing written overwrites the space character.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Apr 2019 17:30:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-an-error-when-using-a-macro-with-paramaters-with-single/m-p/548581#M152128</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-04-04T17:30:01Z</dc:date>
    </item>
    <item>
      <title>Re: Getting an error when using a macro with paramaters with single quotes in CALL EXECUTE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-an-error-when-using-a-macro-with-paramaters-with-single/m-p/548583#M152130</link>
      <description>&lt;P&gt;Very helpful, thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 04 Apr 2019 17:33:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-an-error-when-using-a-macro-with-paramaters-with-single/m-p/548583#M152130</guid>
      <dc:creator>rhachey</dc:creator>
      <dc:date>2019-04-04T17:33:10Z</dc:date>
    </item>
    <item>
      <title>Re: Getting an error when using a macro with paramaters with single quotes in CALL EXECUTE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-an-error-when-using-a-macro-with-paramaters-with-single/m-p/548591#M152136</link>
      <description>&lt;P&gt;The pointer motion is only needed in this case because of the use of the %BQUOTE() function in the generated code.&amp;nbsp; That would quote the trailing space making it part of the value passed to the macro.&amp;nbsp; Since I don't have your macro I am not sure if that extra space would make a difference.&amp;nbsp; Normally in generated SAS code an extra space is not an issue.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you name your macro parameters after your dataset variables (or visa versa) then PUT statement is even easier.&amp;nbsp; So if your macro had two parameters named VAR1 and VAR2 then your metadata dataset should have two variables named VAR1 and VAR2.&lt;/P&gt;
&lt;P&gt;So a program like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
 set metadata ;
 file code;
 put '%macro_name('  var1= ',' var2= ')';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Will create code like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro_name(var1=ABC ,var2=xyz )
%macro_name(var1=DEF ,var2=123 )&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Remember that even if you define your macro to allow the parameters to be specified by position only (like: %my_macro(ABC,xyz) ) you can still use the parameter names in the call to the macro (like:&amp;nbsp;%macro_name(var1=ABC ,var2=xyz ) ).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Apr 2019 17:46:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-an-error-when-using-a-macro-with-paramaters-with-single/m-p/548591#M152136</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-04-04T17:46:24Z</dc:date>
    </item>
  </channel>
</rss>

