<?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 IMPORT not reading inside macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/PROC-IMPORT-not-reading-inside-macro/m-p/831108#M328425</link>
    <description>&lt;P&gt;You have two mistakes.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The main one is that you are not including the period in the generated filename.&amp;nbsp; &amp;nbsp;The period you have is being used by the macro processor so that it knows that the macro variable is named I and IDTA.&amp;nbsp; So you need another one to become part of the filename.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The other are missing semi-colons at the end of two of your macro statements.&amp;nbsp; Macro statements end with semi-colons just like regular SAS statements.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro prep;
%local i;
%do i=1998 %to 2015;
PROC IMPORT DATAFILE = "X:\Rawdata\IND&amp;amp;i..dta"
          OUT = WORK.IND&amp;amp;i
          DBMS=STATA replace
;
RUN;
%end;
%mend; 
%prep;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 30 Aug 2022 14:46:43 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2022-08-30T14:46:43Z</dc:date>
    <item>
      <title>PROC IMPORT not reading inside macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-IMPORT-not-reading-inside-macro/m-p/831103#M328422</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I writing a code to import several .dta files available in a same folder named INDyyyy, with yyyy corresponding to the year. However I am running into problems because SAS does not recognize the PROC IMPORT command inside a macro.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can successfully import each of them individually using the following code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;PROC IMPORT DATAFILE = "X:\Rawdata\IND1998.dta"
OUT = WORK.IND1998
DMS=STATA replace;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The natural step forward is to write a macro and loop over the years:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;%Macro prep;

     %do i=1998 %to 2015

     PROC IMPORT DATAFILE = "X:\Rawdata\IND&amp;amp;i.dta"
          OUT = WORK.IND&amp;amp;i
          DBMS=STATA replace;
          RUN;
     %end
%mend; 
%prep;&lt;/CODE&gt;&lt;CODE class=""&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The problem is that the PROC IMPORT command is not recognized inside of the macro. As you can seen in the screenshot below it is written in black, but when outside it is totally fine.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="PVSCBS_1-1661867837801.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/74851i93AA49721AB824C8/image-size/medium?v=v2&amp;amp;px=400" role="button" title="PVSCBS_1-1661867837801.png" alt="PVSCBS_1-1661867837801.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't understand why this is happening as it seems something similar has been used by several users before, see for example &lt;A href="https://communities.sas.com/t5/SAS-Programming/Proc-importing-multiple-excel-files-using-macro/m-p/808265#M318704" target="_self"&gt;this&lt;/A&gt; post. I also know that the problem is not related to the %do loop because I have removed it from the code and nothing changes.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any idea as to why this is happening? Would you have any other suggestions as far as procedures to import such files?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance for the help&lt;/P&gt;&lt;P&gt;&lt;CODE class=""&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=""&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Aug 2022 14:03:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-IMPORT-not-reading-inside-macro/m-p/831103#M328422</guid>
      <dc:creator>PVSCBS</dc:creator>
      <dc:date>2022-08-30T14:03:53Z</dc:date>
    </item>
    <item>
      <title>Re: PROC IMPORT not reading inside macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-IMPORT-not-reading-inside-macro/m-p/831104#M328423</link>
      <description>&lt;P&gt;You're missing semicolons at the end of the %DO/%END loop.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Aug 2022 14:09:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-IMPORT-not-reading-inside-macro/m-p/831104#M328423</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-08-30T14:09:25Z</dc:date>
    </item>
    <item>
      <title>Re: PROC IMPORT not reading inside macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-IMPORT-not-reading-inside-macro/m-p/831105#M328424</link>
      <description>&lt;P&gt;If you read your log when you run that I will bet you see at least one "File not found" type error message.&lt;/P&gt;
&lt;P&gt;The file name you provide&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;"X:\Rawdata\IND&amp;amp;i.dta"&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;uses the period to delimit the end of the macro variable &amp;amp;i so is generating names like Ind88dta without the period.&lt;/P&gt;
&lt;P&gt;You need to add another period so there is one for the file name&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;"X:\Rawdata\IND&amp;amp;i..dta"&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You do read your logs don't you?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note: many problems with macro coding errors can be seen by setting the system options MPRINT , to show actual generated code, and SYMBOLGEN , to trace construction/use of macro variables.&lt;/P&gt;
&lt;P&gt;So try running:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;options mprint;&lt;/P&gt;
&lt;P&gt;before executing the&amp;nbsp; macro and then reading the log to see error messages in better proximity to the generated code.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Aug 2022 14:10:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-IMPORT-not-reading-inside-macro/m-p/831105#M328424</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-08-30T14:10:42Z</dc:date>
    </item>
    <item>
      <title>Re: PROC IMPORT not reading inside macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-IMPORT-not-reading-inside-macro/m-p/831108#M328425</link>
      <description>&lt;P&gt;You have two mistakes.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The main one is that you are not including the period in the generated filename.&amp;nbsp; &amp;nbsp;The period you have is being used by the macro processor so that it knows that the macro variable is named I and IDTA.&amp;nbsp; So you need another one to become part of the filename.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The other are missing semi-colons at the end of two of your macro statements.&amp;nbsp; Macro statements end with semi-colons just like regular SAS statements.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro prep;
%local i;
%do i=1998 %to 2015;
PROC IMPORT DATAFILE = "X:\Rawdata\IND&amp;amp;i..dta"
          OUT = WORK.IND&amp;amp;i
          DBMS=STATA replace
;
RUN;
%end;
%mend; 
%prep;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 30 Aug 2022 14:46:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-IMPORT-not-reading-inside-macro/m-p/831108#M328425</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-08-30T14:46:43Z</dc:date>
    </item>
  </channel>
</rss>

