<?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 How to Prevent Resolution of Ampersand? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-Prevent-Resolution-of-Ampersand/m-p/866880#M342367</link>
    <description>&lt;P&gt;I have an Excel file &lt;CODE&gt;S&amp;amp;P 500_230328.xlsx&lt;/CODE&gt;&amp;nbsp;on my desktop and want to rename it as &lt;CODE&gt;S&amp;amp;P 500_230329.xlsx&lt;/CODE&gt;&amp;nbsp;via &lt;CODE&gt;infile pipe&lt;/CODE&gt; as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="sas"&gt;data _null_;
	infile "ren %sysget(USERPROFILE)\Desktop\""S%nrstr(&amp;amp;)P 500_%sysfunc(putn(%sysfunc(today()),yymmddn6.))"".xlsx ""S%nrstr(&amp;amp;)P 500_%sysfunc(putn(%sysfunc(today())+1,yymmddn6.))"".xlsx" pipe;
run;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem arises because SAS considers &lt;CODE&gt;&amp;amp;P&lt;/CODE&gt; as a macro expression. I tried both &lt;CODE&gt;%str()&lt;/CODE&gt; and &lt;CODE&gt;%nrstr()&lt;/CODE&gt; for the ampersands above but failed (it seems &lt;CODE&gt;%superq()&lt;/CODE&gt; doesn't work as well); I cannot use single quotes because of the date changes. How can I prevent &lt;CODE&gt;WARNING: Apparent symbolic reference P not resolved.&lt;/CODE&gt; in this case?&lt;/P&gt;</description>
    <pubDate>Tue, 28 Mar 2023 21:37:58 GMT</pubDate>
    <dc:creator>Junyong</dc:creator>
    <dc:date>2023-03-28T21:37:58Z</dc:date>
    <item>
      <title>How to Prevent Resolution of Ampersand?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Prevent-Resolution-of-Ampersand/m-p/866880#M342367</link>
      <description>&lt;P&gt;I have an Excel file &lt;CODE&gt;S&amp;amp;P 500_230328.xlsx&lt;/CODE&gt;&amp;nbsp;on my desktop and want to rename it as &lt;CODE&gt;S&amp;amp;P 500_230329.xlsx&lt;/CODE&gt;&amp;nbsp;via &lt;CODE&gt;infile pipe&lt;/CODE&gt; as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="sas"&gt;data _null_;
	infile "ren %sysget(USERPROFILE)\Desktop\""S%nrstr(&amp;amp;)P 500_%sysfunc(putn(%sysfunc(today()),yymmddn6.))"".xlsx ""S%nrstr(&amp;amp;)P 500_%sysfunc(putn(%sysfunc(today())+1,yymmddn6.))"".xlsx" pipe;
run;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem arises because SAS considers &lt;CODE&gt;&amp;amp;P&lt;/CODE&gt; as a macro expression. I tried both &lt;CODE&gt;%str()&lt;/CODE&gt; and &lt;CODE&gt;%nrstr()&lt;/CODE&gt; for the ampersands above but failed (it seems &lt;CODE&gt;%superq()&lt;/CODE&gt; doesn't work as well); I cannot use single quotes because of the date changes. How can I prevent &lt;CODE&gt;WARNING: Apparent symbolic reference P not resolved.&lt;/CODE&gt; in this case?&lt;/P&gt;</description>
      <pubDate>Tue, 28 Mar 2023 21:37:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Prevent-Resolution-of-Ampersand/m-p/866880#M342367</guid>
      <dc:creator>Junyong</dc:creator>
      <dc:date>2023-03-28T21:37:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to Prevent Resolution of Ampersand?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Prevent-Resolution-of-Ampersand/m-p/866882#M342369</link>
      <description>&lt;P&gt;Use the FILEVAR= option on the INFILE statement so that you can use a data set variable.&amp;nbsp; Then you don't need to bother the macro processor at all.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  length file1 file2 cmd $500 ;
  file1=quote(cats(sysget('USERPROFILE'),'\Desktop\S&amp;amp;P 500_',put(today(),yymmddn6.),'.xlsx'));
  file2=quote(cats('S&amp;amp;P 500_',put(today()+1,yymmddn6.),'.xlsx'));
  cmd=catx(' ','ren',file1,file2);
  infile cmd pipe filevar=cmd ;
  input;
  put _infile_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;PS Why are you generating date strings without the century?&amp;nbsp;&amp;nbsp;&lt;A href="https://en.wikipedia.org/wiki/Year_2000_problem" target="_blank"&gt;https://en.wikipedia.org/wiki/Year_2000_problem&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Mar 2023 21:47:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Prevent-Resolution-of-Ampersand/m-p/866882#M342369</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-03-28T21:47:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to Prevent Resolution of Ampersand?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Prevent-Resolution-of-Ampersand/m-p/866896#M342380</link>
      <description>&lt;P&gt;Thanks—I tend to code Command Prompt and &lt;CODE&gt;pipe&lt;/CODE&gt; directly for readability. It seems that, according to your &lt;CODE&gt;filevar&lt;/CODE&gt; suggestion, this ampersand resolution issue, unlike others, cannot be addressed by &lt;CODE&gt;%str&lt;/CODE&gt;, &lt;CODE&gt;%quote&lt;/CODE&gt;, or &lt;CODE&gt;%superq&lt;/CODE&gt; families.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Mar 2023 23:35:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Prevent-Resolution-of-Ampersand/m-p/866896#M342380</guid>
      <dc:creator>Junyong</dc:creator>
      <dc:date>2023-03-28T23:35:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to Prevent Resolution of Ampersand?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Prevent-Resolution-of-Ampersand/m-p/866915#M342387</link>
      <description>&lt;P&gt;Not sure how complex macro code makes things readable, but you can certainly use %NRSTR() to protect &amp;amp; characters.&amp;nbsp; You just need to remember not to unquote them before you can protect them with actual quotes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use the actual QUOTE() function to add single quotes around the string.&lt;/P&gt;
&lt;PRE&gt;63   %let file1="%sysget(USERPROFILE)\Desktop\%nrstr(S&amp;amp;P) 500_%sysfunc(today(),yymmddn6).xlsx";
64   %let file2="%nrstr(S&amp;amp;P) 500_%sysfunc(putn(%sysfunc(today())+1,yymmddn6.)).xlsx";
65
66   data _null_;
67     infile %sysfunc(quote(ren &amp;amp;file1 &amp;amp;file2,%str(%'))) pipe;
68     input;
69     put _infile_;
70   run;

NOTE: The infile 'ren "C:\Users\xxx\Desktop\S&amp;amp;P 500_230329.xlsx" "S&amp;amp;P 500_230330.xlsx"' is:
      Unnamed Pipe Access Device,
      PROCESS=ren "C:\Users\xxx\Desktop\S&amp;amp;P 500_230329.xlsx" "S&amp;amp;P 500_230330.xlsx",
      RECFM=V,LRECL=32767

Stderr output:
The system cannot find the file specified.
NOTE: 0 records were read from the infile 'ren "C:\Users\xxx\Desktop\S&amp;amp;P 500_230329.xlsx" "S&amp;amp;P 500_230330.xlsx"'.
NOTE: DATA statement used (Total process time):
      real time           0.07 seconds
      cpu time            0.00 seconds
&lt;/PRE&gt;
&lt;P&gt;Or if you know that the string does not contain any single quotes you can use %BQUOTE() to get the single quotes, but you will need to use %unquote() to remove the macro quoting so that SAS can see that you actually passed a quoted string to the INFILE statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  infile %unquote(%bquote('ren &amp;amp;file1 &amp;amp;file2')) pipe;
  input;
  put _infile_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Mar 2023 06:14:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Prevent-Resolution-of-Ampersand/m-p/866915#M342387</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-03-29T06:14:59Z</dc:date>
    </item>
  </channel>
</rss>

