<?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 How do I verify plain text width or delimiter quantity? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-verify-plain-text-width-or-delimiter-quantity/m-p/310724#M67041</link>
    <description>&lt;P&gt;Hi everyone.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm kind of new to SAS programming, I'm using EG 5.1 but have access to 7.1 and I'm having a little problem with a requirement.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm importing a number of plain text files (txt, csv, etc.) into sas datasets, but I'm trying to validate those files before:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;- First, I'm checking the existence of those files.&lt;FONT color="#0000FF"&gt; DONE&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;- Second, I'm counting the number of lines in order to assure the observations number is the expected. &lt;FONT color="#0000FF"&gt;DONE&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;- Third, I want to verifiy that the columns the dataset will have makes sense with the predefined layout of each table. &lt;FONT color="#FF0000"&gt;In process&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So far I think the best, and fastest way to do the third point, is importing the first line of each file and count either width (for fixed-width files) or number of delimiters, depending on each file.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The thing is I'm not sure on how to do this, or if there's a better way of validating what i want. Think you can help me here?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
    <pubDate>Thu, 10 Nov 2016 17:31:03 GMT</pubDate>
    <dc:creator>MilesWhite</dc:creator>
    <dc:date>2016-11-10T17:31:03Z</dc:date>
    <item>
      <title>How do I verify plain text width or delimiter quantity?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-verify-plain-text-width-or-delimiter-quantity/m-p/310724#M67041</link>
      <description>&lt;P&gt;Hi everyone.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm kind of new to SAS programming, I'm using EG 5.1 but have access to 7.1 and I'm having a little problem with a requirement.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm importing a number of plain text files (txt, csv, etc.) into sas datasets, but I'm trying to validate those files before:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;- First, I'm checking the existence of those files.&lt;FONT color="#0000FF"&gt; DONE&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;- Second, I'm counting the number of lines in order to assure the observations number is the expected. &lt;FONT color="#0000FF"&gt;DONE&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;- Third, I want to verifiy that the columns the dataset will have makes sense with the predefined layout of each table. &lt;FONT color="#FF0000"&gt;In process&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So far I think the best, and fastest way to do the third point, is importing the first line of each file and count either width (for fixed-width files) or number of delimiters, depending on each file.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The thing is I'm not sure on how to do this, or if there's a better way of validating what i want. Think you can help me here?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Thu, 10 Nov 2016 17:31:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-verify-plain-text-width-or-delimiter-quantity/m-p/310724#M67041</guid>
      <dc:creator>MilesWhite</dc:creator>
      <dc:date>2016-11-10T17:31:03Z</dc:date>
    </item>
    <item>
      <title>Re: How do I verify plain text width or delimiter quantity?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-verify-plain-text-width-or-delimiter-quantity/m-p/310726#M67042</link>
      <description>&lt;P&gt;Are you planning on using proc import to bring those files into SAS or a datastep?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you use the layout information provided to write data steps to read the data that data step could have additional items to provide diagnostics.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Length of a line may not work for a diagnostic if the file source&amp;nbsp;does not "pad" the end of the data with blanks to the defined length. I have dealt with a number of fixed column files that the last field was not padded.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Likewise a simple count of delimiters may not work, especially if the delimiter is a comma, as the delimeter may occur imbedded with values. CSV usually has quotes around text that contains commas such as " This Company Name, Inc.".&lt;/P&gt;
&lt;P&gt;A data step with well defined Informat statements will often be very helpful for diagnosing some common data problems such as characters in numeric fields or invalid or poorly formatted dates.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Nov 2016 18:24:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-verify-plain-text-width-or-delimiter-quantity/m-p/310726#M67042</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-11-10T18:24:15Z</dc:date>
    </item>
    <item>
      <title>Re: How do I verify plain text width or delimiter quantity?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-verify-plain-text-width-or-delimiter-quantity/m-p/310747#M67045</link>
      <description>&lt;P&gt;Thanks for the answer.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'd prefer not to use a proc import, since as far as I see, it won't be able to detect changes on the files.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for letting me see the problems of doing the validation counting saparators or width, but as the files I'm supposed to import are created by other area, I don´t have total control over the layout, and I want to prevent an&amp;nbsp;uninformed change on it, that's why my best bet was counting.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, the idea is avoiding spend time on importing de data if somthing doesn't make sense and reporting the change to the responsible area on order to dertermine if it was a layout change (solve it by adding the new layout to the code) or a transference error (solve it by re-downloading the file).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So far my report is something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;File&lt;/TD&gt;&lt;TD&gt;Lines&lt;/TD&gt;&lt;TD&gt;Last month's observations&lt;/TD&gt;&lt;TD&gt;Observations&amp;nbsp; diff&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;flie_1&lt;/TD&gt;&lt;TD&gt;1000&lt;/TD&gt;&lt;TD&gt;1001&lt;/TD&gt;&lt;TD&gt;0.10%&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;file_2&lt;/TD&gt;&lt;TD&gt;1500&lt;/TD&gt;&lt;TD&gt;2300&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;34.78%&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;file_3&lt;/TD&gt;&lt;TD&gt;50&lt;/TD&gt;&lt;TD&gt;50&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;0.00%&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And I'm trying to get something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;File&lt;/TD&gt;&lt;TD&gt;Lines&lt;/TD&gt;&lt;TD&gt;Last month's observations&lt;/TD&gt;&lt;TD&gt;Observations&amp;nbsp; diff&lt;/TD&gt;&lt;TD&gt;Apparent columns&lt;/TD&gt;&lt;TD&gt;Last month columns&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;flie_1&lt;/TD&gt;&lt;TD&gt;1000&lt;/TD&gt;&lt;TD&gt;1001&lt;/TD&gt;&lt;TD&gt;0.10%&lt;/TD&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;11&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;file_2&lt;/TD&gt;&lt;TD&gt;1500&lt;/TD&gt;&lt;TD&gt;2300&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;34.78%&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;file_3&lt;/TD&gt;&lt;TD&gt;50&lt;/TD&gt;&lt;TD&gt;50&lt;/TD&gt;&lt;TD&gt;0.00%&lt;/TD&gt;&lt;TD&gt;20&lt;/TD&gt;&lt;TD&gt;20&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Thu, 10 Nov 2016 19:12:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-verify-plain-text-width-or-delimiter-quantity/m-p/310747#M67045</guid>
      <dc:creator>MilesWhite</dc:creator>
      <dc:date>2016-11-10T19:12:08Z</dc:date>
    </item>
    <item>
      <title>Re: How do I verify plain text width or delimiter quantity?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-verify-plain-text-width-or-delimiter-quantity/m-p/310830#M67069</link>
      <description>&lt;P&gt;So far, I've done this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;FILENAME _file_ "&amp;amp;input.&amp;amp;file" ;
data _null_;
   length text $32767;
   retain text '';
   infile _file_ dlmstr='//' end=last flowover lrecl=32767; 
   input;
   text=cats(text,_infile_);
   if _n_=1 then call symput('_file_',text);
   if _n_=1 then call symput('length',length(text));
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;With a few more tweaking and adding an excel with the expected layout, I think I can solve my problem.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Nov 2016 23:46:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-verify-plain-text-width-or-delimiter-quantity/m-p/310830#M67069</guid>
      <dc:creator>MilesWhite</dc:creator>
      <dc:date>2016-11-10T23:46:47Z</dc:date>
    </item>
  </channel>
</rss>

