<?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 Check Multiple files existence from list in data set in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Check-Multiple-files-existence-from-list-in-data-set/m-p/830025#M327955</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;There is a Folder that contain multiple txt daily files with name structure&amp;nbsp; "Offers_YYYYMMDD"&lt;/P&gt;
&lt;P&gt;(For example:&amp;nbsp;Offers_20220701 is file for 01JULY2022 ).&lt;/P&gt;
&lt;P&gt;The files are created almost everyday (non included non-business days and non included cases of fault running).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is a data set called All_Days_tbl&amp;nbsp; that contain all dates between 01JAN2021&amp;nbsp; and Today.&lt;/P&gt;
&lt;P&gt;In this data set there is a column called "path_to_Check"&amp;nbsp; that contain the File name that need to check if it exists or not.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The task is to create&amp;nbsp; a new column called "Indicator_File_Exists"&amp;nbsp; in&amp;nbsp; data set "All_Days_tbl " .&lt;/P&gt;
&lt;P&gt;The column will get value 1 if the file exists and 0 if not .&lt;/P&gt;
&lt;P&gt;Please note that I don't want to read the files (I just need to know which file exists and which not).&lt;/P&gt;
&lt;P&gt;What is the way to do it please?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let start_sas_date="01JAN2021"d;
%let Last_sas_date= "%sysfunc(today(),date9.)"d;
%put &amp;amp;start_sas_date;
%put &amp;amp;Last_sas_date;

data All_Days_tbl_(DROP=end_date);
date=&amp;amp;start_sas_date.;
end_date=&amp;amp;Last_sas_date.;
format date end_date date9.;
do while (date&amp;lt;=end_date);
output;
date=intnx('day', date, 1, 's');
end;
format date date9.;
run;


Data All_Days_tbl;
SET All_Days_tbl_;
path_to_Check=CATS("/usr/local/SAS/offers_daily_Files/Loans.recomend.daily.",put(date,YYMMDDn8.));
Run;

 &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 24 Aug 2022 05:25:40 GMT</pubDate>
    <dc:creator>Ronein</dc:creator>
    <dc:date>2022-08-24T05:25:40Z</dc:date>
    <item>
      <title>Check Multiple files existence from list in data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-Multiple-files-existence-from-list-in-data-set/m-p/830025#M327955</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;There is a Folder that contain multiple txt daily files with name structure&amp;nbsp; "Offers_YYYYMMDD"&lt;/P&gt;
&lt;P&gt;(For example:&amp;nbsp;Offers_20220701 is file for 01JULY2022 ).&lt;/P&gt;
&lt;P&gt;The files are created almost everyday (non included non-business days and non included cases of fault running).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is a data set called All_Days_tbl&amp;nbsp; that contain all dates between 01JAN2021&amp;nbsp; and Today.&lt;/P&gt;
&lt;P&gt;In this data set there is a column called "path_to_Check"&amp;nbsp; that contain the File name that need to check if it exists or not.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The task is to create&amp;nbsp; a new column called "Indicator_File_Exists"&amp;nbsp; in&amp;nbsp; data set "All_Days_tbl " .&lt;/P&gt;
&lt;P&gt;The column will get value 1 if the file exists and 0 if not .&lt;/P&gt;
&lt;P&gt;Please note that I don't want to read the files (I just need to know which file exists and which not).&lt;/P&gt;
&lt;P&gt;What is the way to do it please?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let start_sas_date="01JAN2021"d;
%let Last_sas_date= "%sysfunc(today(),date9.)"d;
%put &amp;amp;start_sas_date;
%put &amp;amp;Last_sas_date;

data All_Days_tbl_(DROP=end_date);
date=&amp;amp;start_sas_date.;
end_date=&amp;amp;Last_sas_date.;
format date end_date date9.;
do while (date&amp;lt;=end_date);
output;
date=intnx('day', date, 1, 's');
end;
format date date9.;
run;


Data All_Days_tbl;
SET All_Days_tbl_;
path_to_Check=CATS("/usr/local/SAS/offers_daily_Files/Loans.recomend.daily.",put(date,YYMMDDn8.));
Run;

 &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Aug 2022 05:25:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-Multiple-files-existence-from-list-in-data-set/m-p/830025#M327955</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2022-08-24T05:25:40Z</dc:date>
    </item>
    <item>
      <title>Re: Check Multiple files existence from list in data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-Multiple-files-existence-from-list-in-data-set/m-p/830026#M327956</link>
      <description>&lt;P&gt;Okay,&lt;/P&gt;
&lt;P&gt;I found the solution.&lt;/P&gt;
&lt;P&gt;Here is the solution.&lt;/P&gt;
&lt;P&gt;If there are other solutions I will be glad to see.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
%let start_sas_date="01JAN2021"d;
%let Last_sas_date= "%sysfunc(today(),date9.)"d;
%put &amp;amp;start_sas_date;
%put &amp;amp;Last_sas_date;
data All_Days_tbl_(DROP=end_date);
date=&amp;amp;start_sas_date.;
end_date=&amp;amp;Last_sas_date.;
format date end_date date9.;
do while (date&amp;lt;=end_date);
output;
date=intnx('day', date, 1, 's');
end;
format date date9.;
run;


Data All_Days_tbl;
SET All_Days_tbl_;
path_to_Check=CATS('"',"/usr/local/SAS/offers_daily_files/Loans.recomend.daily.",put(date,YYMMDDn8.),'"');
Run;
data wanted;
set All_Days_tbl;
IF fileexist(path_to_Check)  then Ind=1;else ind=0;
Run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 24 Aug 2022 05:26:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-Multiple-files-existence-from-list-in-data-set/m-p/830026#M327956</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2022-08-24T05:26:10Z</dc:date>
    </item>
    <item>
      <title>Re: Check Multiple files existence from list in data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-Multiple-files-existence-from-list-in-data-set/m-p/830030#M327959</link>
      <description>&lt;P&gt;No need for any macro variables and only your result data set is needed:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data example;
  length path_to_Check $ 200;
  do date="01JAN2021"d to today();
     path_to_Check=CATS('"',"/usr/local/SAS/offers_daily_files/Loans.recomend.daily.",put(date,YYMMDDn8.),'"');     
     ind = fileexist(path_to_Check);
     output;
  end;
run;&lt;/PRE&gt;
&lt;P&gt;The fileexist returns 1 for found and 0 for not found so the IF /Then/ construct is a waste of clock cycles.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The iterated do will be easier to follow instead of the DO WHILE and avoids any possible infinite loop from a typo involving the incrementing of the dates.&lt;/P&gt;
&lt;P&gt;For most purposes formatted date values just make macro coding difficult. The main usage would be in text that people read such as Title, Footnote text or file names.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Aug 2022 07:17:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-Multiple-files-existence-from-list-in-data-set/m-p/830030#M327959</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-08-24T07:17:23Z</dc:date>
    </item>
  </channel>
</rss>

