<?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: Macro to check if there are 4 files in a given path (with macro variable) in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Macro-to-check-if-there-are-4-files-in-a-given-path-with-macro/m-p/799115#M33127</link>
    <description>&lt;P&gt;Another way:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let myfilerf1=/opt/sas/data/test1_&amp;amp;period..csv;
%let myfilerf2=/opt/sas/data/test2_&amp;amp;period..csv;
%let myfilerf3=/opt/sas/data/test3_&amp;amp;period..csv;
%let myfilerf4=/opt/sas/data/test4_&amp;amp;period..csv;

%global StopExecuting;
%let StopExecuting = 0;

%macro CheckFiles(VarPrefix=);
   data _null_;
      set sashelp.vmacro(where= (Name =: "%upcase(&amp;amp;VarPrefix.)"));
      length FileToTest $ 250;
      
      FileToTest = symget(Name);
      
      if not fileexist(FileToTest) then do;
         put 'ERROR: File ' FileToTest ' does not exist.';
         call symputx('StopExecuting', 1);
      end;
   run;
%mend;

%CheckFiles(VarPrefix= myfilerf);


%macro PROD1;
   %if &amp;amp;StopExecuting %then %return;
   
   /* Anything you want to do if the file exists */

%mend PROD1;

/* ... More macros and macro calls */&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 28 Feb 2022 11:59:19 GMT</pubDate>
    <dc:creator>andreas_lds</dc:creator>
    <dc:date>2022-02-28T11:59:19Z</dc:date>
    <item>
      <title>Macro to check if there are 4 files in a given path (with macro variable)</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-to-check-if-there-are-4-files-in-a-given-path-with-macro/m-p/799098#M33122</link>
      <description>&lt;P&gt;Hello everyone, I'm new to programming in SAS and I would like to add a check if there are 4 files in a given path.&lt;BR /&gt;Files with the same name but different dates will be stored in this folder, for example: 'test1_20210228.csv', the date is stored in a macro variable called &amp;amp;period.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I did before was this:&lt;/P&gt;&lt;PRE&gt;%let myfilerf1=/opt/sas/data/test1_&amp;amp;period..csv;
%let myfilerf2=/opt/sas/data/test2_&amp;amp;period..csv;
%let myfilerf3=/opt/sas/data/test3_&amp;amp;period..csv;
%let myfilerf4=/opt/sas/data/test4_&amp;amp;period..csv;

%macro PROD1;                                                                                                                            
  %if %sysfunc(fileexist(&amp;amp;myfilerf1)) %then %do;                                                                                             
   %put OK;
	%end; 
  %else %do;                                                                                                                                
  %abort cancel; 
	%end; 
%mend PROD1;
%PROD1
%macro PROD2;                                                                                                                            
  %if %sysfunc(fileexist(&amp;amp;myfilerf2)) %then %do;                                                                                             
   %put OK;
	%end; 
  %else %do;                                                                                                                                
  %abort cancel; 
	%end; 
%mend PROD2;
%macro PROD3;                                                                                                                            
  %if %sysfunc(fileexist(&amp;amp;myfilerf3)) %then %do;                                                                                             
   %put OK;
	%end; 
  %else %do;                                                                                                                                
  %abort cancel; 
	%end; 
%mend PROD3;
%macro PROD4;                                                                                                                            
  %if %sysfunc(fileexist(&amp;amp;myfilerf4)) %then %do;                                                                                             
   %put OK;
	%end; 
  %else %do;                                                                                                                                
  %abort cancel; 
	%end; 
%mend PROD4; 
options mprint;                                                                                                                         
%PROD1 
%PROD2 
%PROD3 
%PROD4&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But the problem is that we want to automate this and the abort cancel does not work in batch, so I would like to make a kind of macro or something that sends me an email (I know how to do this) if any of those 4 files do not exist.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I had thought of concatenating the different macros of myfilerf but I don't know how to do it, to make it check if all 4 exist, if they exist, put an OK, if they don't exist, send me an email, but since there are 4 files, I don't want them to I sent 4 emails (1 for each file) so I want to compress everything in a macro if possible, but I don't know how to reference the 4 files for the day that marks &amp;amp;period if inside the fileexist I can only put a macro variable.&lt;/P&gt;&lt;P&gt;Can someone help me with this? I hope I explained myself well, thank you very much in advance&lt;/P&gt;</description>
      <pubDate>Mon, 28 Feb 2022 09:23:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-to-check-if-there-are-4-files-in-a-given-path-with-macro/m-p/799098#M33122</guid>
      <dc:creator>Abelp9</dc:creator>
      <dc:date>2022-02-28T09:23:50Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to check if there are 4 files in a given path (with macro variable)</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-to-check-if-there-are-4-files-in-a-given-path-with-macro/m-p/799113#M33125</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I macro expression can use the AND operator, so you could do something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if %sysfunc(fileexist(&amp;amp;myfilerf1))
  and %sysfunc(fileexist(&amp;amp;myfilerf2))   
  and %sysfunc(fileexist(&amp;amp;myfilerf3))   
  and %sysfunc(fileexist(&amp;amp;myfilerf4)) 
%then %do;
  *... ;
%end;  
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 28 Feb 2022 11:54:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-to-check-if-there-are-4-files-in-a-given-path-with-macro/m-p/799113#M33125</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2022-02-28T11:54:41Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to check if there are 4 files in a given path (with macro variable)</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-to-check-if-there-are-4-files-in-a-given-path-with-macro/m-p/799114#M33126</link>
      <description>&lt;P&gt;Maybe something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro codeYouWantToDoIf4FilesExist();

/* ... YOUR CODE ... */

%mend codeYouWantToDoIf4FilesExist;

%macro test();                                                                                                                            
  %if  %sysfunc(fileexist(&amp;amp;myfilerf1)) 
   AND %sysfunc(fileexist(&amp;amp;myfilerf2))
   AND %sysfunc(fileexist(&amp;amp;myfilerf3))
   AND %sysfunc(fileexist(&amp;amp;myfilerf4))
  %then 
    %do;                                                                                             
      %codeYouWantToDoIf4FilesExist()
  	%end; 
  %else %do;                                                                                                                                
  
    /* code with e-mail */
    
	%end; 
%mend test;

%test()&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All the best&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Mon, 28 Feb 2022 11:55:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-to-check-if-there-are-4-files-in-a-given-path-with-macro/m-p/799114#M33126</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2022-02-28T11:55:52Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to check if there are 4 files in a given path (with macro variable)</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-to-check-if-there-are-4-files-in-a-given-path-with-macro/m-p/799115#M33127</link>
      <description>&lt;P&gt;Another way:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let myfilerf1=/opt/sas/data/test1_&amp;amp;period..csv;
%let myfilerf2=/opt/sas/data/test2_&amp;amp;period..csv;
%let myfilerf3=/opt/sas/data/test3_&amp;amp;period..csv;
%let myfilerf4=/opt/sas/data/test4_&amp;amp;period..csv;

%global StopExecuting;
%let StopExecuting = 0;

%macro CheckFiles(VarPrefix=);
   data _null_;
      set sashelp.vmacro(where= (Name =: "%upcase(&amp;amp;VarPrefix.)"));
      length FileToTest $ 250;
      
      FileToTest = symget(Name);
      
      if not fileexist(FileToTest) then do;
         put 'ERROR: File ' FileToTest ' does not exist.';
         call symputx('StopExecuting', 1);
      end;
   run;
%mend;

%CheckFiles(VarPrefix= myfilerf);


%macro PROD1;
   %if &amp;amp;StopExecuting %then %return;
   
   /* Anything you want to do if the file exists */

%mend PROD1;

/* ... More macros and macro calls */&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 28 Feb 2022 11:59:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-to-check-if-there-are-4-files-in-a-given-path-with-macro/m-p/799115#M33127</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2022-02-28T11:59:19Z</dc:date>
    </item>
  </channel>
</rss>

