<?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: Quotation mark in quoted macro variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Quotation-mark-in-quoted-macro-variable/m-p/667726#M200023</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/286185"&gt;@SASdevAnneMarie&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Hello Richard,&lt;BR /&gt;&lt;BR /&gt;It is just a short example, for understanding the probleme. It is NOT a real code, I need the quotation mark beacause I code the ods object report. &lt;BR /&gt;Thank you!&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If the macro variable value COULD have quote character and you want to add quotes around it do not use:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put "&amp;amp;mvar";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Instead use the QUOTE() function.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put %sysfunc(quote(&amp;amp;mvar));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that the QUOTE() function now supports a second parameter to tell it what quote character to use on the outside. So if the macro variable value could contain macro triggers like &amp;amp; or % then use single quotes on the outside to prevent the macro processor from trying to evaluate them as macro variable or macro function references.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put %sysfunc(quote(&amp;amp;mvar,%str(%')));&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 08 Jul 2020 14:37:29 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2020-07-08T14:37:29Z</dc:date>
    <item>
      <title>Quotation mark in quoted macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Quotation-mark-in-quoted-macro-variable/m-p/667656#M199984</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a quoted macro variable PRODUIT (see the code), with a quotation mark inside.&lt;/P&gt;
&lt;P&gt;Do you know how to resolve correctly this macro variable?&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;
&lt;P&gt;data test;&lt;BR /&gt;input X1 $5.;&lt;BR /&gt;cards;&lt;BR /&gt;"cd3"&lt;BR /&gt;"cd4"&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;%macro my_var;&lt;/P&gt;
&lt;P&gt;DATA _null_;&lt;BR /&gt;SET test END=eof;&lt;/P&gt;
&lt;P&gt;IF eof THEN&lt;BR /&gt;DO;&lt;BR /&gt;CALL SYMPUT('nb',put(_N_,8.));&lt;BR /&gt;END;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;%do i=1 %to &amp;amp;nb.;&lt;/P&gt;
&lt;P&gt;data _NULL_;&lt;BR /&gt;set test(obs=&amp;amp;i);&lt;BR /&gt;CALL SYMPUTX('PRODUIT',X1);&lt;BR /&gt;run;&lt;BR /&gt;%put "&amp;amp;PRODUIT.";&lt;BR /&gt;%end;&lt;/P&gt;
&lt;P&gt;%mend;&lt;/P&gt;
&lt;P&gt;%my_var;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you very much!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jul 2020 09:02:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Quotation-mark-in-quoted-macro-variable/m-p/667656#M199984</guid>
      <dc:creator>SASdevAnneMarie</dc:creator>
      <dc:date>2020-07-08T09:02:24Z</dc:date>
    </item>
    <item>
      <title>Re: Quotation mark in quoted macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Quotation-mark-in-quoted-macro-variable/m-p/667658#M199986</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/286185"&gt;@SASdevAnneMarie&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a quoted macro variable PRODUIT (see the code), with a quotation mark inside.&lt;/P&gt;
&lt;P&gt;Do you know how to resolve correctly this macro variable?&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;
&lt;P&gt;data test;&lt;BR /&gt;input X1 $5.;&lt;BR /&gt;cards;&lt;BR /&gt;"cd3"&lt;BR /&gt;"cd4"&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;%macro my_var;&lt;/P&gt;
&lt;P&gt;DATA _null_;&lt;BR /&gt;SET test END=eof;&lt;/P&gt;
&lt;P&gt;IF eof THEN&lt;BR /&gt;DO;&lt;BR /&gt;CALL SYMPUT('nb',put(_N_,8.));&lt;BR /&gt;END;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;%do i=1 %to &amp;amp;nb.;&lt;/P&gt;
&lt;P&gt;data _NULL_;&lt;BR /&gt;set test(obs=&amp;amp;i);&lt;BR /&gt;CALL SYMPUTX('PRODUIT',X1);&lt;BR /&gt;run;&lt;BR /&gt;%put "&amp;amp;PRODUIT.";&lt;BR /&gt;%end;&lt;/P&gt;
&lt;P&gt;%mend;&lt;/P&gt;
&lt;P&gt;%my_var;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you very much!&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Don't use the additional double quotes in the %PUT:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put &amp;amp;PRODUIT.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jul 2020 09:09:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Quotation-mark-in-quoted-macro-variable/m-p/667658#M199986</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-07-08T09:09:07Z</dc:date>
    </item>
    <item>
      <title>Re: Quotation mark in quoted macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Quotation-mark-in-quoted-macro-variable/m-p/667659#M199987</link>
      <description>Hello,&lt;BR /&gt;&lt;BR /&gt;I need the additional quotation mark, beacause,, I use "&amp;amp;PRODUIT." in ods code&lt;BR /&gt;It is just a short example  )&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 08 Jul 2020 09:19:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Quotation-mark-in-quoted-macro-variable/m-p/667659#M199987</guid>
      <dc:creator>SASdevAnneMarie</dc:creator>
      <dc:date>2020-07-08T09:19:10Z</dc:date>
    </item>
    <item>
      <title>Re: Quotation mark in quoted macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Quotation-mark-in-quoted-macro-variable/m-p/667660#M199988</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Try using DEQUOTE.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;CALL SYMPUTX('PRODUIT', DEQUOTE(X1) );&lt;/PRE&gt;
&lt;P&gt;The rest of your code is a real hodgepodge and indicates maybe you need to learn a bit more before jumping into macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example:&lt;/P&gt;
&lt;P&gt;This is the WRONG WAY to get the number of observations in a data set&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;DATA _null_;
SET test END=eof;

IF eof THEN
DO;
CALL SYMPUT('nb',put(_N_,8.));
END;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Without knowing the planned use of the macro I speculate this is too much overwriting of the target macro symbol PRODUIT&lt;/P&gt;
&lt;PRE&gt;%do i=1 %to &amp;amp;nb.;

data _NULL_;
set test(obs=&amp;amp;i);
* CALL SYMPUTX('PRODUIT',X1);     &lt;BR /&gt;  CALL SYMPUTX('PRODUIT',DEQUOTE(X1));    %* Regardless, this is where DEQUOTE might go;
run;
%put "&amp;amp;PRODUIT.";
%end;&lt;/PRE&gt;</description>
      <pubDate>Wed, 08 Jul 2020 09:19:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Quotation-mark-in-quoted-macro-variable/m-p/667660#M199988</guid>
      <dc:creator>RichardDeVen</dc:creator>
      <dc:date>2020-07-08T09:19:57Z</dc:date>
    </item>
    <item>
      <title>Re: Quotation mark in quoted macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Quotation-mark-in-quoted-macro-variable/m-p/667662#M199990</link>
      <description>&lt;P&gt;Having quotes in macro variables is always a BAD IDEA.&lt;/P&gt;
&lt;P&gt;Having&amp;nbsp;&lt;EM&gt;double&lt;/EM&gt; quotes in macro variables is a&amp;nbsp;&lt;STRONG&gt;DOUBLE BAD IDEA&lt;/STRONG&gt;, as you have experienced.&lt;/P&gt;
&lt;P&gt;Please show us how you want to use that macro variable in your ODS code.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jul 2020 09:32:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Quotation-mark-in-quoted-macro-variable/m-p/667662#M199990</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-07-08T09:32:24Z</dc:date>
    </item>
    <item>
      <title>Re: Quotation mark in quoted macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Quotation-mark-in-quoted-macro-variable/m-p/667663#M199991</link>
      <description>Hello Richard,&lt;BR /&gt;&lt;BR /&gt;It is just a short example, for understanding the probleme. It is NOT a real code, I need the quotation mark beacause I code the ods object report. &lt;BR /&gt;Thank you!</description>
      <pubDate>Wed, 08 Jul 2020 09:36:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Quotation-mark-in-quoted-macro-variable/m-p/667663#M199991</guid>
      <dc:creator>SASdevAnneMarie</dc:creator>
      <dc:date>2020-07-08T09:36:54Z</dc:date>
    </item>
    <item>
      <title>Re: Quotation mark in quoted macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Quotation-mark-in-quoted-macro-variable/m-p/667726#M200023</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/286185"&gt;@SASdevAnneMarie&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Hello Richard,&lt;BR /&gt;&lt;BR /&gt;It is just a short example, for understanding the probleme. It is NOT a real code, I need the quotation mark beacause I code the ods object report. &lt;BR /&gt;Thank you!&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If the macro variable value COULD have quote character and you want to add quotes around it do not use:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put "&amp;amp;mvar";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Instead use the QUOTE() function.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put %sysfunc(quote(&amp;amp;mvar));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that the QUOTE() function now supports a second parameter to tell it what quote character to use on the outside. So if the macro variable value could contain macro triggers like &amp;amp; or % then use single quotes on the outside to prevent the macro processor from trying to evaluate them as macro variable or macro function references.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put %sysfunc(quote(&amp;amp;mvar,%str(%')));&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 08 Jul 2020 14:37:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Quotation-mark-in-quoted-macro-variable/m-p/667726#M200023</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-07-08T14:37:29Z</dc:date>
    </item>
    <item>
      <title>Re: Quotation mark in quoted macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Quotation-mark-in-quoted-macro-variable/m-p/667734#M200029</link>
      <description>&lt;P&gt;Thank you Richard!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm trying to do that for "real" code but I still have the same error:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="MarieT_0-1594219970326.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/47001iA037AD325EBA1D67/image-size/medium?v=v2&amp;amp;px=400" role="button" title="MarieT_0-1594219970326.png" alt="MarieT_0-1594219970326.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;NOTE: Line generated by the macro variable "PROFILE_NAME".&lt;BR /&gt;919 "Profilée Non "Sécuritaire"&lt;BR /&gt;____________________________________________________&lt;BR /&gt;49 388&lt;BR /&gt;202&lt;BR /&gt;ERROR: DATA STEP Component Object failure. Aborted during the COMPILATION phase.&lt;BR /&gt;NOTE 49-169: The meaning of an identifier after a quoted string might change in a future SAS release. Inserting white space &lt;BR /&gt;between a quoted string and the succeeding identifier is recommended.&lt;/P&gt;
&lt;P&gt;ERROR 388-185: Expecting an arithmetic operator.&lt;/P&gt;
&lt;P&gt;ERROR 202-322: The option or parameter is not recognized and will be ignored.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jul 2020 14:55:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Quotation-mark-in-quoted-macro-variable/m-p/667734#M200029</guid>
      <dc:creator>SASdevAnneMarie</dc:creator>
      <dc:date>2020-07-08T14:55:40Z</dc:date>
    </item>
    <item>
      <title>Re: Quotation mark in quoted macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Quotation-mark-in-quoted-macro-variable/m-p/667739#M200034</link>
      <description>&lt;P&gt;So if the macro variable does NOT have macro quoting already (which I thought you said it did in your original post) then you need to add that before passing the value to the QUOTE() function.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%sysfunc(quote(%superq(MVAR)))&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that %SUPERQ() wants the NAME of the macro variable, not its value.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jul 2020 15:07:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Quotation-mark-in-quoted-macro-variable/m-p/667739#M200034</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-07-08T15:07:42Z</dc:date>
    </item>
    <item>
      <title>Re: Quotation mark in quoted macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Quotation-mark-in-quoted-macro-variable/m-p/667762#M200045</link>
      <description>Thank you! That works!&lt;BR /&gt;</description>
      <pubDate>Wed, 08 Jul 2020 15:37:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Quotation-mark-in-quoted-macro-variable/m-p/667762#M200045</guid>
      <dc:creator>SASdevAnneMarie</dc:creator>
      <dc:date>2020-07-08T15:37:13Z</dc:date>
    </item>
    <item>
      <title>Re: Quotation mark in quoted macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Quotation-mark-in-quoted-macro-variable/m-p/667792#M200055</link>
      <description>Which is the best way in your opinion to get the number of observations please in this case? &lt;BR /&gt;Thank you for your help!</description>
      <pubDate>Wed, 08 Jul 2020 17:33:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Quotation-mark-in-quoted-macro-variable/m-p/667792#M200055</guid>
      <dc:creator>SASdevAnneMarie</dc:creator>
      <dc:date>2020-07-08T17:33:23Z</dc:date>
    </item>
    <item>
      <title>Re: Quotation mark in quoted macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Quotation-mark-in-quoted-macro-variable/m-p/667794#M200056</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
call symputx('nobs',nobs);
set test nobs=nobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You need to do the call symputx before an eventual end-of-file (when there are zero observations) causes the immediate termination of the data step.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jul 2020 17:43:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Quotation-mark-in-quoted-macro-variable/m-p/667794#M200056</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-07-08T17:43:57Z</dc:date>
    </item>
    <item>
      <title>Re: Quotation mark in quoted macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Quotation-mark-in-quoted-macro-variable/m-p/667895#M200101</link>
      <description>Thank you very much!</description>
      <pubDate>Wed, 08 Jul 2020 22:37:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Quotation-mark-in-quoted-macro-variable/m-p/667895#M200101</guid>
      <dc:creator>SASdevAnneMarie</dc:creator>
      <dc:date>2020-07-08T22:37:20Z</dc:date>
    </item>
  </channel>
</rss>

