<?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: Bypass an empty file when Importing multiple files into a dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Bypass-an-empty-file-when-Importing-multiple-files-into-a/m-p/519305#M140647</link>
    <description>&lt;P&gt;You could test the file before processing:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  call symputx ('file_contains_data',_N_-1);
  infile "%sysfunc(pathname(WORK))\t.txt" obs=2 firstobs=2;  
  input; 
run; 
%put &amp;amp;=file_contains_data;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 06 Dec 2018 22:40:47 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2018-12-06T22:40:47Z</dc:date>
    <item>
      <title>Bypass an empty file when Importing multiple files into a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Bypass-an-empty-file-when-Importing-multiple-files-into-a/m-p/519285#M140637</link>
      <description>&lt;P&gt;I am importing multiple files in a database and I received a file with only headers and zero records. How can I bypass the file if it is empty?&lt;/P&gt;</description>
      <pubDate>Thu, 06 Dec 2018 21:22:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Bypass-an-empty-file-when-Importing-multiple-files-into-a/m-p/519285#M140637</guid>
      <dc:creator>amyk</dc:creator>
      <dc:date>2018-12-06T21:22:59Z</dc:date>
    </item>
    <item>
      <title>Re: Bypass an empty file when Importing multiple files into a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Bypass-an-empty-file-when-Importing-multiple-files-into-a/m-p/519301#M140646</link>
      <description>&lt;P&gt;Please explain... If the file is empty, it should contribute 0 records to your database when it is imported.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Dec 2018 22:27:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Bypass-an-empty-file-when-Importing-multiple-files-into-a/m-p/519301#M140646</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-12-06T22:27:54Z</dc:date>
    </item>
    <item>
      <title>Re: Bypass an empty file when Importing multiple files into a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Bypass-an-empty-file-when-Importing-multiple-files-into-a/m-p/519305#M140647</link>
      <description>&lt;P&gt;You could test the file before processing:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  call symputx ('file_contains_data',_N_-1);
  infile "%sysfunc(pathname(WORK))\t.txt" obs=2 firstobs=2;  
  input; 
run; 
%put &amp;amp;=file_contains_data;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Dec 2018 22:40:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Bypass-an-empty-file-when-Importing-multiple-files-into-a/m-p/519305#M140647</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-12-06T22:40:47Z</dc:date>
    </item>
    <item>
      <title>Re: Bypass an empty file when Importing multiple files into a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Bypass-an-empty-file-when-Importing-multiple-files-into-a/m-p/519325#M140651</link>
      <description>&lt;P&gt;Please show how you are currently importing the non-empty files.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Dec 2018 00:04:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Bypass-an-empty-file-when-Importing-multiple-files-into-a/m-p/519325#M140651</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-12-07T00:04:17Z</dc:date>
    </item>
    <item>
      <title>Re: Bypass an empty file when Importing multiple files into a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Bypass-an-empty-file-when-Importing-multiple-files-into-a/m-p/519382#M140666</link>
      <description>&lt;P&gt;I have created three files:&lt;/P&gt;
&lt;P&gt;test1.csv:&lt;/P&gt;
&lt;PRE&gt;vara,varb
1,2
3,4
&lt;/PRE&gt;
&lt;P&gt;test2.csv:&lt;/P&gt;
&lt;PRE&gt;vara,varb&lt;/PRE&gt;
&lt;P&gt;test3.csv:&lt;/P&gt;
&lt;PRE&gt;vara,varb
5,6
7,8
&lt;/PRE&gt;
&lt;P&gt;Importing all files of similar structure in one data step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want1;
infile '$HOME/sascommunity/test*.csv' dlm=',' dsd truncover;
input @;
if not index(_infile_,'vara');
input vara varb;
run;

proc print data=want1 noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;vara    varb

  1       2 
  3       4 
  5       6 
  7       8 
&lt;/PRE&gt;
&lt;P&gt;The empty file was successfully "skipped".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Importing a single file and determining if empty on the fly:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want2;
infile '$HOME/sascommunity/test2.csv' dlm=',' dsd truncover firstobs=2;
retain count 0;
call symputx('count',count);
input vara varb;
count + 1;
drop count;
run;

%if &amp;amp;count %then %do;
/* further processing of dataset */
%end;

%if not &amp;amp;count %then %do;
%put empty!;
%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Log:&lt;/P&gt;
&lt;PRE&gt;27         data want2;
28         infile '$HOME/sascommunity/test2.csv' dlm=',' dsd truncover firstobs=2;
29         retain count 0;
30         call symputx('count',count);
31         input vara varb;
32         count + 1;
33         drop count;
34         run;

NOTE: The infile '$HOME/sascommunity/test2.csv' is:
      Dateiname=/wadaten/home/e9782/sascommunity/test2.csv,
      Besitzername=e9782,Gruppenname=sasadmin,
      Zugriffsberechtigung=-rw-r--r--,
      Zuletzt geändert=07. Dezember 2018 09.42 Uhr,
      Dateigröße (Byte)=10

NOTE: 0 records were read from the infile '$HOME/sascommunity/test2.csv'.
NOTE: The data set WORK.WANT2 has 0 observations and 3 variables.
NOTE: DATA statement used (Total process time):
      real time           0.04 seconds
      cpu time            0.00 seconds
      

35         
36         %if &amp;amp;count %then %do;
37         /* further processing of dataset */
38         %end;
39         
40         %if not &amp;amp;count %then %do;
41         %put empty!;
empty!
42         %end;
&lt;/PRE&gt;</description>
      <pubDate>Fri, 07 Dec 2018 08:58:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Bypass-an-empty-file-when-Importing-multiple-files-into-a/m-p/519382#M140666</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-12-07T08:58:38Z</dc:date>
    </item>
  </channel>
</rss>

