<?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: How to pass value with a single quote (French elision symbol) to a macro? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-pass-value-with-a-single-quote-French-elision-symbol-to-a/m-p/828114#M327117</link>
    <description>&lt;P&gt;The easiest way is to code the macro to expect (or at least allow) the parameter to be passed with actual quotes.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test(obj=);
%let obj=%sysfunc(quote(%qsysfunc(dequote(&amp;amp;obj)),%str(%')));
proc print data=sashelp.class;
  where name = &amp;amp;obj ;
run;

%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then use the QUOTE() function in your data step to add the quotes to the generated macro call.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_ ;
  set test ;
  call execute(cats('%nrstr(%test)(obj=',quote(trim(mvar),"'"),')'));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;696   options mprint;
697   data _null_ ;
698     do mvar='Alfred','Alice';
699       call execute(cats('%nrstr(%test)(obj=',quote(trim(mvar),"'"),')'));
700     end;
701   run;

NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


NOTE: CALL EXECUTE generated line.
1    + %test(obj='Alfred')
MPRINT(TEST):   proc print data=sashelp.class;
MPRINT(TEST):   where name = 'Alfred' ;
MPRINT(TEST):   run;

NOTE: There were 1 observations read from the data set SASHELP.CLASS.
      WHERE name='Alfred';
NOTE: PROCEDURE PRINT used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


2    + %test(obj='Alice')
MPRINT(TEST):   proc print data=sashelp.class;
MPRINT(TEST):   where name = 'Alice' ;
MPRINT(TEST):   run;

NOTE: There were 1 observations read from the data set SASHELP.CLASS.
      WHERE name='Alice';
NOTE: PROCEDURE PRINT used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
&lt;/PRE&gt;</description>
    <pubDate>Wed, 10 Aug 2022 15:53:52 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2022-08-10T15:53:52Z</dc:date>
    <item>
      <title>How to pass value with a single quote (French elision symbol) to a macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pass-value-with-a-single-quote-French-elision-symbol-to-a/m-p/828110#M327116</link>
      <description>&lt;P&gt;There a dataset. I need to call a macro for every value of a certain column. This column has some values with an "elision" French symbol which is like an unmatched single quote. How can I pass this value to a macro in a loop using call execute?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is an example:&lt;/P&gt;
&lt;P&gt;/* Initial dataset. Need to loop over its values. In reality this dataset has many rows. */&lt;/P&gt;
&lt;P&gt;data test;&lt;BR /&gt;mvar="L'université";&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;/* Macro to call for every row in the dataset. */&lt;/P&gt;
&lt;P&gt;%macro test(obj=);&lt;/P&gt;
&lt;P&gt;/* Some code...*/&lt;BR /&gt;%put &amp;amp;obj.;&lt;/P&gt;
&lt;P&gt;%mend;&lt;/P&gt;
&lt;P&gt;/* Loop to call macro for every row in the dataset. */&lt;BR /&gt;data _null_ ;&lt;BR /&gt;set test ;&lt;BR /&gt;str=catt('%test(obj=%nrstr(',mvar,'));');&lt;BR /&gt;call execute(str);&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This code results in errors:&lt;/P&gt;
&lt;P&gt;ERROR: Expected close parenthesis after macro function invocation not found.&lt;BR /&gt;ERROR: Macro parameter contains syntax error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for any help.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Aug 2022 15:34:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pass-value-with-a-single-quote-French-elision-symbol-to-a/m-p/828110#M327116</guid>
      <dc:creator>pavelr</dc:creator>
      <dc:date>2022-08-10T15:34:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass value with a single quote (French elision symbol) to a macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pass-value-with-a-single-quote-French-elision-symbol-to-a/m-p/828114#M327117</link>
      <description>&lt;P&gt;The easiest way is to code the macro to expect (or at least allow) the parameter to be passed with actual quotes.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test(obj=);
%let obj=%sysfunc(quote(%qsysfunc(dequote(&amp;amp;obj)),%str(%')));
proc print data=sashelp.class;
  where name = &amp;amp;obj ;
run;

%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then use the QUOTE() function in your data step to add the quotes to the generated macro call.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_ ;
  set test ;
  call execute(cats('%nrstr(%test)(obj=',quote(trim(mvar),"'"),')'));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;696   options mprint;
697   data _null_ ;
698     do mvar='Alfred','Alice';
699       call execute(cats('%nrstr(%test)(obj=',quote(trim(mvar),"'"),')'));
700     end;
701   run;

NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


NOTE: CALL EXECUTE generated line.
1    + %test(obj='Alfred')
MPRINT(TEST):   proc print data=sashelp.class;
MPRINT(TEST):   where name = 'Alfred' ;
MPRINT(TEST):   run;

NOTE: There were 1 observations read from the data set SASHELP.CLASS.
      WHERE name='Alfred';
NOTE: PROCEDURE PRINT used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


2    + %test(obj='Alice')
MPRINT(TEST):   proc print data=sashelp.class;
MPRINT(TEST):   where name = 'Alice' ;
MPRINT(TEST):   run;

NOTE: There were 1 observations read from the data set SASHELP.CLASS.
      WHERE name='Alice';
NOTE: PROCEDURE PRINT used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
&lt;/PRE&gt;</description>
      <pubDate>Wed, 10 Aug 2022 15:53:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pass-value-with-a-single-quote-French-elision-symbol-to-a/m-p/828114#M327117</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-08-10T15:53:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass value with a single quote (French elision symbol) to a macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pass-value-with-a-single-quote-French-elision-symbol-to-a/m-p/828211#M327153</link>
      <description>&lt;P&gt;Thanks, this will work for my case!&lt;/P&gt;</description>
      <pubDate>Thu, 11 Aug 2022 06:30:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pass-value-with-a-single-quote-French-elision-symbol-to-a/m-p/828211#M327153</guid>
      <dc:creator>pavelr</dc:creator>
      <dc:date>2022-08-11T06:30:05Z</dc:date>
    </item>
  </channel>
</rss>

