<?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: include multiple SAS files with a do loop in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/include-multiple-SAS-files-with-a-do-loop/m-p/215787#M267670</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;First, to address your original question ... you need three dots instead of two:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%include "&amp;amp;macro_folder.\&amp;amp;&amp;amp;macro_&amp;amp;i...sas";&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The first dot delimits &amp;amp;i, the second delimits &amp;amp;macro_1, and the third becomes text.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;More important, you need to look at the subject known as the AUTOCALL facility.&amp;nbsp; If your macros are "properly" defined, you don't need to %include any of them.&amp;nbsp; "Properly" defined means that write_access.sas defines %write_access, NIS_surveymeans.sas defines %NIS_surveymeans, etc.&amp;nbsp; In that case, just add one statement to your program:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;options sasautos="&amp;amp;macro_folder";&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then all the macros in that folder will automatically be available to the program.&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 03 Aug 2015 22:40:47 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2015-08-03T22:40:47Z</dc:date>
    <item>
      <title>include multiple SAS files with a do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/include-multiple-SAS-files-with-a-do-loop/m-p/215784#M267667</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You wouldn't bother to write a loop for including SAS files when there are just few. However, I have &amp;gt;50 to do. For each file, I have used a %let to name the file in a macro variable, and a %include to bring it to the current SAS session as the following:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="php" __jive_macro_name="code" class="jive_text_macro jive_macro_code _jivemacro_uid_14386146992151633" jivemacro_uid="_14386146992151633" modifiedtitle="true"&gt;
&lt;P&gt;%let macro_folder&amp;nbsp;&amp;nbsp;&amp;nbsp; =&amp;nbsp;&amp;nbsp;&amp;nbsp; C:\SAS_macros_chang;&lt;/P&gt;
&lt;P&gt;%let macro_1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; =&amp;nbsp;&amp;nbsp;&amp;nbsp; write_access.sas;&lt;/P&gt;
&lt;P&gt;%let macro_2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; =&amp;nbsp;&amp;nbsp;&amp;nbsp; NIS_surveymeans.sas;&lt;/P&gt;
&lt;P&gt;%let macro_3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; =&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NIS_surveyfreq.sas;&lt;/P&gt;
&lt;P&gt;%let macro_4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; =&amp;nbsp;&amp;nbsp;&amp;nbsp; reshape_univar_long2wide.sas;&lt;/P&gt;
&lt;P&gt;%let macro_5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; =&amp;nbsp;&amp;nbsp;&amp;nbsp; duplicate_APPEND.sas;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;%include "&amp;amp;macro_folder.\&amp;amp;macro_1.";&lt;/P&gt;
&lt;P&gt;%include "&amp;amp;macro_folder.\&amp;amp;macro_2.";&lt;/P&gt;
&lt;P&gt;%include "&amp;amp;macro_folder.\&amp;amp;macro_3.";&lt;/P&gt;
&lt;P&gt;%include "&amp;amp;macro_folder.\&amp;amp;macro_4.";&lt;/P&gt;
&lt;P&gt;%include "&amp;amp;macro_folder.\&amp;amp;macro_5.";&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have attempted to replace the five pairs of %let and %include with the following code but just can't get SAS include the files correctly.&lt;/P&gt;&lt;PRE __default_attr="php" __jive_macro_name="code" class="jive_text_macro jive_macro_code _jivemacro_uid_14386153525167121" jivemacro_uid="_14386153525167121" modifiedtitle="true"&gt;
&lt;P&gt;%sysmacdelete include_many_files; &lt;/P&gt;
&lt;P&gt;%macro include_many_files;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let list= write_access NIS_surveymeans NIS_surveyfreq reshape_univar_long2wide duplicate_APPEND ; &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let n = %sysfunc(countw(&amp;amp;list.)) ; &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %do i= 1 %to &amp;amp;n. ;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let macro_&amp;amp;i. = %scan(&amp;amp;list., &amp;amp;i.) ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %include "&amp;amp;macro_folder.\&amp;amp;&amp;amp;macro_&amp;amp;i..sas" ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;&lt;/P&gt;
&lt;P&gt;%mend include_many_files;&lt;/P&gt;
&lt;P&gt;%include_many_files;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is the log. Apparently the file extension .sas is not there. I am not sure why my two periods can't get it right. &lt;/P&gt;&lt;P&gt;WARNING: Physical file does not exist, C:\SAS_macros_chang\write_accesssas.&lt;/P&gt;&lt;P&gt;ERROR: Cannot open %INCLUDE file C:\SAS_macros_chang\write_accesssas.&lt;/P&gt;&lt;P&gt;WARNING: Physical file does not exist, C:\SAS_macros_chang\NIS_surveymeanssas.&lt;/P&gt;&lt;P&gt;ERROR: Cannot open %INCLUDE file C:\SAS_macros_chang\NIS_surveymeanssas.&lt;/P&gt;&lt;P&gt;WARNING: Physical file does not exist, C:\SAS_macros_chang\NIS_surveyfreqsas.&lt;/P&gt;&lt;P&gt;ERROR: Cannot open %INCLUDE file C:\SAS_macros_chang\NIS_surveyfreqsas.&lt;/P&gt;&lt;P&gt;WARNING: Physical file does not exist, C:\SAS_macros_chang\reshape_univar_long2widesas.&lt;/P&gt;&lt;P&gt;ERROR: Cannot open %INCLUDE file C:\SAS_macros_chang\reshape_univar_long2widesas.&lt;/P&gt;&lt;P&gt;WARNING: Physical file does not exist, C:\SAS_macros_chang\duplicate_APPENDsas.&lt;/P&gt;&lt;P&gt;ERROR: Cannot open %INCLUDE file C:\SAS_macros_chang\duplicate_APPENDsas.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any advice would be highly appreciated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Chang&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 03 Aug 2015 15:28:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/include-multiple-SAS-files-with-a-do-loop/m-p/215784#M267667</guid>
      <dc:creator>Chang</dc:creator>
      <dc:date>2015-08-03T15:28:23Z</dc:date>
    </item>
    <item>
      <title>Re: include multiple SAS files with a do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/include-multiple-SAS-files-with-a-do-loop/m-p/215785#M267668</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try this&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro include_many_files;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let list= write_access NIS_surveymeans NIS_surveyfreq reshape_univar_long2wide duplicate_APPEND ;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let n = %sysfunc(countw(&amp;amp;list.)) ;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %do i= 1 %to &amp;amp;n ;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %include "&amp;amp;macro_folder.\%scan(&amp;amp;list, &amp;amp;i).sas" ;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;&amp;nbsp; &lt;/P&gt;&lt;P&gt;%mend include_many_files;&amp;nbsp; &lt;/P&gt;&lt;P&gt;%include_many_files;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope it helps,&lt;/P&gt;&lt;P&gt;Ahmed&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 03 Aug 2015 16:23:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/include-multiple-SAS-files-with-a-do-loop/m-p/215785#M267668</guid>
      <dc:creator>AhmedAl_Attar</dc:creator>
      <dc:date>2015-08-03T16:23:07Z</dc:date>
    </item>
    <item>
      <title>Re: include multiple SAS files with a do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/include-multiple-SAS-files-with-a-do-loop/m-p/215786#M267669</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;%let macro_folder&amp;nbsp;&amp;nbsp;&amp;nbsp; =&amp;nbsp;&amp;nbsp;&amp;nbsp; C:\SAS_macros_chang;&amp;nbsp; &lt;/P&gt;&lt;P&gt;filename code "&amp;amp;macro_folder";&lt;/P&gt;&lt;P&gt;%include code( &lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;write_access &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;NIS_surveymeans &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;NIS_surveyfreq &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;reshape_univar_long2wide &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;duplicate_APPEND) / source2 ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 03 Aug 2015 17:42:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/include-multiple-SAS-files-with-a-do-loop/m-p/215786#M267669</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2015-08-03T17:42:45Z</dc:date>
    </item>
    <item>
      <title>Re: include multiple SAS files with a do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/include-multiple-SAS-files-with-a-do-loop/m-p/215787#M267670</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;First, to address your original question ... you need three dots instead of two:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%include "&amp;amp;macro_folder.\&amp;amp;&amp;amp;macro_&amp;amp;i...sas";&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The first dot delimits &amp;amp;i, the second delimits &amp;amp;macro_1, and the third becomes text.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;More important, you need to look at the subject known as the AUTOCALL facility.&amp;nbsp; If your macros are "properly" defined, you don't need to %include any of them.&amp;nbsp; "Properly" defined means that write_access.sas defines %write_access, NIS_surveymeans.sas defines %NIS_surveymeans, etc.&amp;nbsp; In that case, just add one statement to your program:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;options sasautos="&amp;amp;macro_folder";&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then all the macros in that folder will automatically be available to the program.&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 03 Aug 2015 22:40:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/include-multiple-SAS-files-with-a-do-loop/m-p/215787#M267670</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2015-08-03T22:40:47Z</dc:date>
    </item>
    <item>
      <title>Re: include multiple SAS files with a do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/include-multiple-SAS-files-with-a-do-loop/m-p/483583#M267671</link>
      <description>&lt;P&gt;Does this work?&lt;/P&gt;</description>
      <pubDate>Thu, 02 Aug 2018 20:31:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/include-multiple-SAS-files-with-a-do-loop/m-p/483583#M267671</guid>
      <dc:creator>petlove</dc:creator>
      <dc:date>2018-08-02T20:31:24Z</dc:date>
    </item>
  </channel>
</rss>

