<?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 adding percent chars to macrovariable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/adding-percent-chars-to-macrovariable/m-p/761406#M240937</link>
    <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to execute a sql using like condition, That means i need to add % signs to the condition string. I having a hard time figure out how to do it.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a macrovariable that has the value&amp;nbsp; "tablename"&lt;/P&gt;
&lt;P&gt;what i want to do is to put % chars before and in the end of the string. I have tried using %str,%nrquote and %quote&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let tb="tablername";&lt;BR /&gt;%let likecondition=%str(%&amp;amp;tb%);&lt;BR /&gt;%put likecondition;&lt;/P&gt;
&lt;P&gt;I have also tried compress but it seems that i cannot mask the % as string.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;have&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"tablername"&lt;/P&gt;
&lt;P&gt;want&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"%tablename%"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How do i do this in sas macro or data step if that is preferred.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 13 Aug 2021 12:41:47 GMT</pubDate>
    <dc:creator>havmaage</dc:creator>
    <dc:date>2021-08-13T12:41:47Z</dc:date>
    <item>
      <title>adding percent chars to macrovariable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/adding-percent-chars-to-macrovariable/m-p/761406#M240937</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to execute a sql using like condition, That means i need to add % signs to the condition string. I having a hard time figure out how to do it.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a macrovariable that has the value&amp;nbsp; "tablename"&lt;/P&gt;
&lt;P&gt;what i want to do is to put % chars before and in the end of the string. I have tried using %str,%nrquote and %quote&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let tb="tablername";&lt;BR /&gt;%let likecondition=%str(%&amp;amp;tb%);&lt;BR /&gt;%put likecondition;&lt;/P&gt;
&lt;P&gt;I have also tried compress but it seems that i cannot mask the % as string.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;have&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"tablername"&lt;/P&gt;
&lt;P&gt;want&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"%tablename%"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How do i do this in sas macro or data step if that is preferred.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Aug 2021 12:41:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/adding-percent-chars-to-macrovariable/m-p/761406#M240937</guid>
      <dc:creator>havmaage</dc:creator>
      <dc:date>2021-08-13T12:41:47Z</dc:date>
    </item>
    <item>
      <title>Re: adding percent chars to macrovariable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/adding-percent-chars-to-macrovariable/m-p/761408#M240939</link>
      <description>&lt;P&gt;You need a double percent sign to result in the single-percent sign in the output, see&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmmvacdc/9.4/mcrolref/n09tblrxldh8k0n1kt6dkj3xlxug.htm" target="_blank" rel="noopener"&gt;https://documentation.sas.com/doc/en/pgmmvacdc/9.4/mcrolref/n09tblrxldh8k0n1kt6dkj3xlxug.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let tb=tablername;
%let likecondition="%nrstr(%%)&amp;amp;tb%nrstr(%%)";

%put &amp;amp;=tb;
%put &amp;amp;=likecondition;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Except for rare cases, I would not enclose the value of a macro variable in quotes or double-quotes, so I would use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let tb=tablername;
%let likecondition=%nrstr(%%)&amp;amp;tb%nrstr(%%);

%put &amp;amp;=tb;
%put &amp;amp;=likecondition;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and then use &lt;FONT face="courier new,courier"&gt;"&amp;amp;likecondition"&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Aug 2021 12:51:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/adding-percent-chars-to-macrovariable/m-p/761408#M240939</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-08-13T12:51:44Z</dc:date>
    </item>
    <item>
      <title>Re: adding percent chars to macrovariable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/adding-percent-chars-to-macrovariable/m-p/761413#M240942</link>
      <description>&lt;P&gt;Is there some reason the first macro variable includes the quotes?&amp;nbsp; If it does include the quotes and you want the % inside the quotes you probably need to first remove the quotes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But you probably would like to include single quotes around the value with the % in it to prevent the macro processor from typing to call a macro with the same name as the table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you can use a data step it is easier since you don't have to worry about the fighting the macro processor.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if you already have the table name in a dataset and want to generate a macro variable use something like:&lt;/P&gt;
&lt;PRE&gt;18    data _null_;
19      tb="tablename";
20      call symputx('likecondition',quote(cats('%',tb,'%'),"'"));
21    run;

NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


22
23    %put &amp;amp;=likecondition;
LIKECONDITION='%tablename%'
&lt;/PRE&gt;</description>
      <pubDate>Fri, 13 Aug 2021 13:15:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/adding-percent-chars-to-macrovariable/m-p/761413#M240942</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-08-13T13:15:54Z</dc:date>
    </item>
  </channel>
</rss>

