<?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: Proc-importing multiple excel files using %macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-importing-multiple-excel-files-using-macro/m-p/808269#M318707</link>
    <description>&lt;P&gt;You have two problems. The major one regards quotes. Macro variables do no resolve inside single quotes.&lt;/P&gt;
&lt;P&gt;Second, the macro language uses the . (dot) to indicate the end of a macro variable in conjunction with other text. So when you have macro variable such as &amp;amp;index.xls the . would be removed and the resolved text would be come File1xls with no dot before the file extension. So when using that construct you need two dots.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So you code likely should look like:&lt;/P&gt;
&lt;PRE&gt;%MACRO import(index);
   proc import datafile="C:/Users/somebody/Desktop/Country data/&amp;amp;index..xls"
     dbms=xls out=&amp;amp;index replace; 
   run; 
%MEND import;&lt;/PRE&gt;
&lt;P&gt;Please post code in a text or code box opened on the forum with the &amp;lt;/&amp;gt; or running man icon. The message windows will reformat text making it harder to read and follow.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can see the code generated by your macro by using OPTIONS MPRINT; before executing the macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If these XLS (really!?) files are supposed to be of the same structure for variable names, types and lengths do not be surprised that the data sets generated by Proc Import do not agree as each file is processed separately.&lt;/P&gt;</description>
    <pubDate>Mon, 18 Apr 2022 14:54:41 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2022-04-18T14:54:41Z</dc:date>
    <item>
      <title>Proc-importing multiple excel files using %macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-importing-multiple-excel-files-using-macro/m-p/808265#M318704</link>
      <description>&lt;P&gt;Hi, all,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Greetings,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I hope you are enjoying a snug weekend evening;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you guys simply check why this code is not working?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%MACRO import(index); &lt;BR /&gt;proc import datafile='C:/Users/somebody/Desktop/Country data/&amp;amp;index.xls'&lt;BR /&gt;dbms=xls out=&amp;amp;index replace; run; %MEND import;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then, I tried to execute macro %import as follows:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;%import(file1); %import(file2); %import(brabra.... etc.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, it didn't work, and what I got was only&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ERROR: Physical file does not exist, C:/Users/somebody/Desktop/Country data/&amp;amp;index.xls&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What seems to be a problem in this coding?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you in advance!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sincerely,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;KS -,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Apr 2022 01:31:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-importing-multiple-excel-files-using-macro/m-p/808265#M318704</guid>
      <dc:creator>KS99</dc:creator>
      <dc:date>2022-04-18T01:31:37Z</dc:date>
    </item>
    <item>
      <title>Re: Proc-importing multiple excel files using %macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-importing-multiple-excel-files-using-macro/m-p/808269#M318707</link>
      <description>&lt;P&gt;You have two problems. The major one regards quotes. Macro variables do no resolve inside single quotes.&lt;/P&gt;
&lt;P&gt;Second, the macro language uses the . (dot) to indicate the end of a macro variable in conjunction with other text. So when you have macro variable such as &amp;amp;index.xls the . would be removed and the resolved text would be come File1xls with no dot before the file extension. So when using that construct you need two dots.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So you code likely should look like:&lt;/P&gt;
&lt;PRE&gt;%MACRO import(index);
   proc import datafile="C:/Users/somebody/Desktop/Country data/&amp;amp;index..xls"
     dbms=xls out=&amp;amp;index replace; 
   run; 
%MEND import;&lt;/PRE&gt;
&lt;P&gt;Please post code in a text or code box opened on the forum with the &amp;lt;/&amp;gt; or running man icon. The message windows will reformat text making it harder to read and follow.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can see the code generated by your macro by using OPTIONS MPRINT; before executing the macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If these XLS (really!?) files are supposed to be of the same structure for variable names, types and lengths do not be surprised that the data sets generated by Proc Import do not agree as each file is processed separately.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Apr 2022 14:54:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-importing-multiple-excel-files-using-macro/m-p/808269#M318707</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-04-18T14:54:41Z</dc:date>
    </item>
    <item>
      <title>Re: Proc-importing multiple excel files using %macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-importing-multiple-excel-files-using-macro/m-p/808271#M318708</link>
      <description>&lt;P&gt;The log error message shows that the macrovar &amp;amp;index is not being seen by the macro processor, so it is not resolved&amp;nbsp; (e.g. you want &lt;EM&gt;&lt;STRONG&gt;&amp;amp;index&lt;/STRONG&gt;&lt;/EM&gt; to be resolved to &lt;EM&gt;&lt;STRONG&gt;file1&lt;/STRONG&gt;&lt;/EM&gt;).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That's because your macro code has single quotes in this line:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc import datafile='C:/Users/somebody/Desktop/Country data/&amp;amp;index.xls'&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;which should probably have double quotes as in&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc import datafile="C:/Users/somebody/Desktop/Country data/&amp;amp;index..xls"&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The double quotes will allow the macro parser to look inside the quoted text and resolve &lt;EM&gt;&lt;STRONG&gt;&amp;amp;index&lt;/STRONG&gt;&lt;/EM&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also note that the single &lt;STRONG&gt;.&lt;/STRONG&gt; after &lt;EM&gt;&lt;STRONG&gt;&amp;amp;index&lt;/STRONG&gt;&lt;/EM&gt;, it now has a double &lt;STRONG&gt;..&amp;nbsp; &amp;nbsp;&lt;/STRONG&gt;- which allows&amp;nbsp;the first &lt;STRONG&gt;.&lt;/STRONG&gt; to serve as a macrovar terminator, therefore requiring a second &lt;STRONG&gt;.&lt;/STRONG&gt; to be part of the final file name ending with ".xls".&lt;/P&gt;</description>
      <pubDate>Mon, 18 Apr 2022 02:49:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-importing-multiple-excel-files-using-macro/m-p/808271#M318708</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-04-18T02:49:49Z</dc:date>
    </item>
    <item>
      <title>Re: Proc-importing multiple excel files using %macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-importing-multiple-excel-files-using-macro/m-p/808272#M318709</link>
      <description>&lt;P&gt;In addition to the other issues raised:&lt;/P&gt;
&lt;P&gt;- Windows paths typically use back slashes not forward slashes, although most likely they will still work.&lt;/P&gt;
&lt;P&gt;- If your SAS session is running on a remote SAS server you can't write to your own desktop drives. You will have to use a folder the remote server recognises.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Apr 2022 03:15:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-importing-multiple-excel-files-using-macro/m-p/808272#M318709</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2022-04-18T03:15:47Z</dc:date>
    </item>
    <item>
      <title>Re: Proc-importing multiple excel files using %macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-importing-multiple-excel-files-using-macro/m-p/808480#M318801</link>
      <description>Thank you so much, ballardw! &lt;BR /&gt;I wish you a very good week! &lt;BR /&gt;&lt;BR /&gt;KS -</description>
      <pubDate>Tue, 19 Apr 2022 04:23:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-importing-multiple-excel-files-using-macro/m-p/808480#M318801</guid>
      <dc:creator>KS99</dc:creator>
      <dc:date>2022-04-19T04:23:37Z</dc:date>
    </item>
    <item>
      <title>Re: Proc-importing multiple excel files using %macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-importing-multiple-excel-files-using-macro/m-p/808481#M318802</link>
      <description>I really appreciate your comments, mkeintz! &lt;BR /&gt;Wish you a very good evening! &lt;BR /&gt;&lt;BR /&gt;Sincerely, &lt;BR /&gt;KS -, &lt;BR /&gt;</description>
      <pubDate>Tue, 19 Apr 2022 04:24:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-importing-multiple-excel-files-using-macro/m-p/808481#M318802</guid>
      <dc:creator>KS99</dc:creator>
      <dc:date>2022-04-19T04:24:30Z</dc:date>
    </item>
    <item>
      <title>Re: Proc-importing multiple excel files using %macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-importing-multiple-excel-files-using-macro/m-p/808482#M318803</link>
      <description>Thank you SASkiwi! &lt;BR /&gt;&lt;BR /&gt;I will keep them in mind! &lt;BR /&gt;&lt;BR /&gt;Sincerely, &lt;BR /&gt;KS -, &lt;BR /&gt;</description>
      <pubDate>Tue, 19 Apr 2022 04:25:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-importing-multiple-excel-files-using-macro/m-p/808482#M318803</guid>
      <dc:creator>KS99</dc:creator>
      <dc:date>2022-04-19T04:25:05Z</dc:date>
    </item>
  </channel>
</rss>

