<?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 all text files have same number of fields when reading multiple datasets in using wildcard in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Check-all-text-files-have-same-number-of-fields-when-reading/m-p/535751#M6530</link>
    <description>&lt;P&gt;Hi!&amp;nbsp; I am reading in several text files using a wildcard in the infile statement and I include additional statements to store the name of the file in a separate variable.&amp;nbsp; Each text file includes the variable names&amp;nbsp;in the first row.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA work.test
     LENGTH filename txt_file_name $256;
     RETAIN txt_file_name;
     INFILE "C:\samplepath\*.txt" 
          EOV = eov
          FILENAME = filename
          DLM = ","
          MISSOVER
          DSD
          LRECL = 32767;
     INPUT@;
          IF _N_ = 1 OR EOV THEN DO;
               txt_file_name = scan(filename, -1,"\");
               EOV = 0;
               DELETE;
               END;
          ELSE
       INPUT .....&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The files that I am reading in 'should' all have the same structure.&amp;nbsp;&amp;nbsp;Is there&amp;nbsp;a way to test within this data step that the files being read in all have the same number of variables? I am trying to avoid reading them all in separately and checking that way.&amp;nbsp; I was&amp;nbsp;thinking that replacing the MISSOVER option with the STOPOVER option might work, but I get an error message "INPUT statement exceeded record length."&amp;nbsp; Any help is greatly appreciated.&amp;nbsp; Thanks!&lt;/P&gt;</description>
    <pubDate>Thu, 14 Feb 2019 21:03:05 GMT</pubDate>
    <dc:creator>bh11</dc:creator>
    <dc:date>2019-02-14T21:03:05Z</dc:date>
    <item>
      <title>Check all text files have same number of fields when reading multiple datasets in using wildcard</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Check-all-text-files-have-same-number-of-fields-when-reading/m-p/535751#M6530</link>
      <description>&lt;P&gt;Hi!&amp;nbsp; I am reading in several text files using a wildcard in the infile statement and I include additional statements to store the name of the file in a separate variable.&amp;nbsp; Each text file includes the variable names&amp;nbsp;in the first row.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA work.test
     LENGTH filename txt_file_name $256;
     RETAIN txt_file_name;
     INFILE "C:\samplepath\*.txt" 
          EOV = eov
          FILENAME = filename
          DLM = ","
          MISSOVER
          DSD
          LRECL = 32767;
     INPUT@;
          IF _N_ = 1 OR EOV THEN DO;
               txt_file_name = scan(filename, -1,"\");
               EOV = 0;
               DELETE;
               END;
          ELSE
       INPUT .....&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The files that I am reading in 'should' all have the same structure.&amp;nbsp;&amp;nbsp;Is there&amp;nbsp;a way to test within this data step that the files being read in all have the same number of variables? I am trying to avoid reading them all in separately and checking that way.&amp;nbsp; I was&amp;nbsp;thinking that replacing the MISSOVER option with the STOPOVER option might work, but I get an error message "INPUT statement exceeded record length."&amp;nbsp; Any help is greatly appreciated.&amp;nbsp; Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 14 Feb 2019 21:03:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Check-all-text-files-have-same-number-of-fields-when-reading/m-p/535751#M6530</guid>
      <dc:creator>bh11</dc:creator>
      <dc:date>2019-02-14T21:03:05Z</dc:date>
    </item>
    <item>
      <title>Re: Check all text files have same number of fields when reading multiple datasets in using wildcard</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Check-all-text-files-have-same-number-of-fields-when-reading/m-p/535757#M6531</link>
      <description>&lt;P&gt;Try something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Make flat files to play with */
title; footnote;
ods csvall file="C:\temp\t1.txt";
proc print data=sashelp.class(where=(Sex='F')) noobs;
run;
ods csvall close;
ods csvall file="C:\temp\t2.txt";
proc print data=sashelp.class(where=(Sex='M')) noobs;
run;
ods csvall close;
data _null_;
   file "C:\temp\t3.txt" dsd ;
   set sashelp.class (obs=3);
   if _n_=1 then put '"Name","Sex","Height","Weight"';
   put Name Sex Height Weight;
run;

/* Proof of Concept */
DATA work.test;
     LENGTH filename txt_file_name _header _last_header $ 256;
     RETAIN txt_file_name _header _last_header ;
     drop _:;
     INFILE "C:\temp\t*.txt" 
          EOV = eov
          FILENAME = filename
          DLM = ","
          MISSOVER
          DSD
          LRECL = 32767;
     INPUT@;
          IF _N_ = 1 OR EOV THEN DO;
               txt_file_name = scan(filename, -1,"\");
               EOV = 0;
               _header=_infile_;
               if _last_header ne _header and _n_ ne 1 then do;
                  PUT "ERROR: File structure for " txt_file_name " has changed.";
                  PUT "ERROR- New file structure:      " _header;
                  PUT "ERROR- Previous file structure: " _last_header;
                  stop;
               end;
               _last_header=_header;
               DELETE;
          END;
          ELSE INPUT Name:$15. Sex:$1. Age Height Weight;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Feb 2019 21:28:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Check-all-text-files-have-same-number-of-fields-when-reading/m-p/535757#M6531</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2019-02-14T21:28:43Z</dc:date>
    </item>
    <item>
      <title>Re: Check all text files have same number of fields when reading multiple datasets in using wildcard</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Check-all-text-files-have-same-number-of-fields-when-reading/m-p/535761#M6532</link>
      <description>&lt;P&gt;I tested this using sample datasets I created where there was a variable removed, a variable added, and a variable name changed. Once I adjusted the LENGTH statement (the _header and _last_header variables&amp;nbsp;were very long for my datasets) this worked perfectly.&amp;nbsp; Thanks! &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Feb 2019 22:08:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Check-all-text-files-have-same-number-of-fields-when-reading/m-p/535761#M6532</guid>
      <dc:creator>bh11</dc:creator>
      <dc:date>2019-02-14T22:08:59Z</dc:date>
    </item>
  </channel>
</rss>

