<?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 Import multiple files if exists in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Import-multiple-files-if-exists/m-p/611961#M178476</link>
    <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I need to import&amp;nbsp; many txt files into sas&lt;/P&gt;
&lt;P&gt;The files exists almost every day and I need to import files for each month in dates : 02,05,10,20,25&lt;/P&gt;
&lt;P&gt;The name of the tables is looking like that: tblYYMMDD&lt;/P&gt;
&lt;P&gt;so for example:&lt;/P&gt;
&lt;P&gt;From Janunary 2019 I need to import files:&lt;/P&gt;
&lt;P&gt;tbl190102&amp;nbsp;&lt;/P&gt;
&lt;P&gt;tbl190105&amp;nbsp;&lt;/P&gt;
&lt;P&gt;tbl190110&lt;/P&gt;
&lt;P&gt;tbl190120&lt;/P&gt;
&lt;P&gt;tbl190125&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The problem is that sometimes the file doesn't exist and then I need to import a file from one day after (and if not exists then 2 days after....etc)&lt;/P&gt;
&lt;P&gt;For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;bl190105&amp;nbsp; is not existing so I need to import&amp;nbsp;&amp;nbsp;bl190106&lt;/P&gt;
&lt;P&gt;tbl190125&amp;nbsp;is not existing&amp;nbsp; and also&amp;nbsp;&amp;nbsp;tbl190126 is not exisiting so i need to import&amp;nbsp;tbl190127&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please find the basic code .&lt;/P&gt;
&lt;P&gt;I need to find solution for 2 problems:&lt;/P&gt;
&lt;P&gt;1-How to make more efficient code that create the dates that need to import (instead of the long %let that I created)&lt;/P&gt;
&lt;P&gt;2-How to tell SAS that if the file doesn't exist then need to import 1 day after and if 1 day after doen't exist then 2 days after ...(maximum 5 days later....)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
%let vector1=190102+190105+190110+190115+190120+190125
			 +190202+190205+190210+190215+190220+190225  
			 +190302+190305+190310+190315+190320+190325  
			 +190402+190405+190410+190415+190420+190425  
			 +190502+190505+190510+190515+190520+190525  
			 +190602+190605+190610+190615+190620+190625  
			 +190702+190705+190710+190715+190720+190725  
 			 +190802+190805+190810+190815+190820+190825  
 			 +190902+190905+190910+190915+190920+190925  
 			 +191002+191005+191010+191015+191020+191025  
 			 +191102+191105+191110+191115+191120+191125;  

%let  k=%sysfunc(countw(&amp;amp;vector1));
%put &amp;amp;k.;


%macro mmacro1; 
%do j=1 %to &amp;amp;k.;
%let YYMMDD=%scan(&amp;amp;vector1.,&amp;amp;j.,+);
data Hamlatzot&amp;amp;YYMMDD.;
infile "Path.tbl&amp;amp;YYMMDD." LRECL=54 recfm=f;
input 
X1     s370fzd8.
X2     $ebcdic1.
X3   	   s370fzd3.
X4      s370fzd9.
X5  s370fzd8.
X6     s370fzd5.
X7        $20.;
run;
%end;
%mend;
%mmacro1; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 16 Dec 2019 06:30:39 GMT</pubDate>
    <dc:creator>Ronein</dc:creator>
    <dc:date>2019-12-16T06:30:39Z</dc:date>
    <item>
      <title>Import multiple files if exists</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-multiple-files-if-exists/m-p/611961#M178476</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I need to import&amp;nbsp; many txt files into sas&lt;/P&gt;
&lt;P&gt;The files exists almost every day and I need to import files for each month in dates : 02,05,10,20,25&lt;/P&gt;
&lt;P&gt;The name of the tables is looking like that: tblYYMMDD&lt;/P&gt;
&lt;P&gt;so for example:&lt;/P&gt;
&lt;P&gt;From Janunary 2019 I need to import files:&lt;/P&gt;
&lt;P&gt;tbl190102&amp;nbsp;&lt;/P&gt;
&lt;P&gt;tbl190105&amp;nbsp;&lt;/P&gt;
&lt;P&gt;tbl190110&lt;/P&gt;
&lt;P&gt;tbl190120&lt;/P&gt;
&lt;P&gt;tbl190125&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The problem is that sometimes the file doesn't exist and then I need to import a file from one day after (and if not exists then 2 days after....etc)&lt;/P&gt;
&lt;P&gt;For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;bl190105&amp;nbsp; is not existing so I need to import&amp;nbsp;&amp;nbsp;bl190106&lt;/P&gt;
&lt;P&gt;tbl190125&amp;nbsp;is not existing&amp;nbsp; and also&amp;nbsp;&amp;nbsp;tbl190126 is not exisiting so i need to import&amp;nbsp;tbl190127&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please find the basic code .&lt;/P&gt;
&lt;P&gt;I need to find solution for 2 problems:&lt;/P&gt;
&lt;P&gt;1-How to make more efficient code that create the dates that need to import (instead of the long %let that I created)&lt;/P&gt;
&lt;P&gt;2-How to tell SAS that if the file doesn't exist then need to import 1 day after and if 1 day after doen't exist then 2 days after ...(maximum 5 days later....)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
%let vector1=190102+190105+190110+190115+190120+190125
			 +190202+190205+190210+190215+190220+190225  
			 +190302+190305+190310+190315+190320+190325  
			 +190402+190405+190410+190415+190420+190425  
			 +190502+190505+190510+190515+190520+190525  
			 +190602+190605+190610+190615+190620+190625  
			 +190702+190705+190710+190715+190720+190725  
 			 +190802+190805+190810+190815+190820+190825  
 			 +190902+190905+190910+190915+190920+190925  
 			 +191002+191005+191010+191015+191020+191025  
 			 +191102+191105+191110+191115+191120+191125;  

%let  k=%sysfunc(countw(&amp;amp;vector1));
%put &amp;amp;k.;


%macro mmacro1; 
%do j=1 %to &amp;amp;k.;
%let YYMMDD=%scan(&amp;amp;vector1.,&amp;amp;j.,+);
data Hamlatzot&amp;amp;YYMMDD.;
infile "Path.tbl&amp;amp;YYMMDD." LRECL=54 recfm=f;
input 
X1     s370fzd8.
X2     $ebcdic1.
X3   	   s370fzd3.
X4      s370fzd9.
X5  s370fzd8.
X6     s370fzd5.
X7        $20.;
run;
%end;
%mend;
%mmacro1; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Dec 2019 06:30:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-multiple-files-if-exists/m-p/611961#M178476</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2019-12-16T06:30:39Z</dc:date>
    </item>
    <item>
      <title>Re: Import multiple files if exists</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-multiple-files-if-exists/m-p/611975#M178481</link>
      <description>&lt;P&gt;Please have a look at this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro mmacro1(YYMMDD=); 
   data Hamlatzot&amp;amp;YYMMDD.;
      infile "Path.tbl&amp;amp;YYMMDD." LRECL=54 recfm=f;
      input 
         X1     s370fzd8.
         X2     $ebcdic1.
         X3   	   s370fzd3.
         X4      s370fzd9.
         X5  s370fzd8.
         X6     s370fzd5.
         X7        $20.
      ;
   run;
%mend;

%let month = 1;
%let year = 2019;

data _null_;
   length name $ 20 date 8;
   format date yymmddn6.;
   do day = 2,5,10,20,25;
      date = mdy(&amp;amp;month., day, &amp;amp;year.);
      name = cats('tbl', vvalue(date));

      do while (not fileexist(cats("&amp;amp;path/", name)));
         date = date + 1;
         name = cats('tbl', vvalue(date));
      end;

      call execute(cats('%nrstr(%mmacro1(yymmdd=', vvalue(date), '))'));
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The outer-loop in the data step tries to find a file as close as possible to the days you named. As soon as a file is found, your macro is called via call execute.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Dec 2019 08:36:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-multiple-files-if-exists/m-p/611975#M178481</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2019-12-16T08:36:46Z</dc:date>
    </item>
  </channel>
</rss>

