<?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: how to get max line length from multiple .sas files? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-get-max-line-length-from-multiple-sas-files/m-p/665798#M199126</link>
    <description>&lt;P&gt;Thank you very much! It works, only the file names are blank in the end table for some reason. What can cause this?&lt;/P&gt;</description>
    <pubDate>Mon, 29 Jun 2020 14:17:40 GMT</pubDate>
    <dc:creator>ger15xxhcker</dc:creator>
    <dc:date>2020-06-29T14:17:40Z</dc:date>
    <item>
      <title>how to get max line length from multiple .sas files?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-get-max-line-length-from-multiple-sas-files/m-p/665780#M199116</link>
      <description>&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a folder with multiple .sas file and I want to know what the maximum length of a line is per file.&lt;/P&gt;&lt;P&gt;for e.g:&lt;/P&gt;&lt;P&gt;a&amp;nbsp; 255&lt;/P&gt;&lt;P&gt;b 100&lt;/P&gt;&lt;P&gt;c 300&lt;/P&gt;&lt;P&gt;How can i get that?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your help!&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jun 2020 13:17:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-get-max-line-length-from-multiple-sas-files/m-p/665780#M199116</guid>
      <dc:creator>ger15xxhcker</dc:creator>
      <dc:date>2020-06-29T13:17:06Z</dc:date>
    </item>
    <item>
      <title>Re: how to get max line length from multiple .sas files?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-get-max-line-length-from-multiple-sas-files/m-p/665787#M199118</link>
      <description>&lt;P&gt;What do you mean by &lt;STRONG&gt;.sas files&lt;/STRONG&gt;? - the suffix .sas is given to program files, and in a program you can split lines to shorten them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you meant sas datasets, then the observations have variable length but you don't need to care of it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The only meaning I can imagine is for maximum length of a char type variable present in multiple datasets. Is that what you are looking for?&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jun 2020 13:56:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-get-max-line-length-from-multiple-sas-files/m-p/665787#M199118</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-06-29T13:56:59Z</dc:date>
    </item>
    <item>
      <title>Re: how to get max line length from multiple .sas files?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-get-max-line-length-from-multiple-sas-files/m-p/665791#M199120</link>
      <description>&lt;P&gt;Thanks for your reply. These are sas program files. Text files.&lt;/P&gt;&lt;DIV&gt;&lt;DIV class="gtx-trans-icon"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Mon, 29 Jun 2020 14:00:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-get-max-line-length-from-multiple-sas-files/m-p/665791#M199120</guid>
      <dc:creator>ger15xxhcker</dc:creator>
      <dc:date>2020-06-29T14:00:18Z</dc:date>
    </item>
    <item>
      <title>Re: how to get max line length from multiple .sas files?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-get-max-line-length-from-multiple-sas-files/m-p/665795#M199123</link>
      <description>&lt;P&gt;Just read the files.&amp;nbsp; Do you have the list of files? Or do you just want to read all .sas files in one directory?&amp;nbsp; Here is the later.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   length fname filename $256 ;
   infile '/mydir/*.sas' truncover length=ll filename=fname end=eof;
   retain max_length 0 max_non_blank 0 filename ;
   input ;
   if _n_&amp;gt;1 and fname ne lag(fname) then do;
      output;
      max_length=0;
      max_non_blank=0;
   end;
   filename=fname;
   max_length=max(max_length,ll);
   max_non_blank = max(max_non_blank,lengthn(_infile_));
   if eof then output;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;STRONG&gt;Updated&lt;/STRONG&gt;:&amp;nbsp; Added FILENAME to retain statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note: If you are using Windows operating system the '*.sas' will match filenames with extensions that start with .sas, for example SAS datasets use .sas7bdat extension.&amp;nbsp; So add more conditions on the OUTPUT statements.&amp;nbsp; Or use some other method to get the list of files.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if lowcase(scan(filename,-1,'.')) = 'sas' then output;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 29 Jun 2020 14:33:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-get-max-line-length-from-multiple-sas-files/m-p/665795#M199123</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-06-29T14:33:37Z</dc:date>
    </item>
    <item>
      <title>Re: how to get max line length from multiple .sas files?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-get-max-line-length-from-multiple-sas-files/m-p/665797#M199125</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/192091"&gt;@ger15xxhcker&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks for your reply. These are sas program files. Text files.&lt;/P&gt;
&lt;DIV&gt;
&lt;DIV class="gtx-trans-icon"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Depending on number of program files:&lt;BR /&gt;If there are few programs you can read them concatenated in one filename statement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;filename all_p ("&amp;lt;path and file1.sas&amp;gt;"&amp;nbsp;&amp;nbsp;"&amp;lt;path and file2.sas&amp;gt;" ...);&lt;/P&gt;
&lt;P&gt;otherwise define a filename for each program, read it as a text file.&lt;/P&gt;
&lt;P&gt;Assign row with max+ supposed length (try $char500.) and check the real length&lt;/P&gt;
&lt;P&gt;using function&amp;nbsp;&lt;STRONG&gt;length(&lt;/STRONG&gt;row&lt;STRONG&gt;) &lt;/STRONG&gt;and retain the max length by:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;retain max_length 0;
max_length = max(max_length, length(row));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you need more help, post your code and log to show what issues you have.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jun 2020 14:17:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-get-max-line-length-from-multiple-sas-files/m-p/665797#M199125</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-06-29T14:17:42Z</dc:date>
    </item>
    <item>
      <title>Re: how to get max line length from multiple .sas files?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-get-max-line-length-from-multiple-sas-files/m-p/665798#M199126</link>
      <description>&lt;P&gt;Thank you very much! It works, only the file names are blank in the end table for some reason. What can cause this?&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jun 2020 14:17:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-get-max-line-length-from-multiple-sas-files/m-p/665798#M199126</guid>
      <dc:creator>ger15xxhcker</dc:creator>
      <dc:date>2020-06-29T14:17:40Z</dc:date>
    </item>
    <item>
      <title>Re: how to get max line length from multiple .sas files?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-get-max-line-length-from-multiple-sas-files/m-p/665799#M199127</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/192091"&gt;@ger15xxhcker&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks for your reply. These are sas program files. Text files.&lt;/P&gt;
&lt;DIV&gt;
&lt;DIV class="gtx-trans-icon"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You may need to define what you mean by "line length". Is it actually the text line or a statement ?&lt;/P&gt;
&lt;P&gt;Since a SAS statement ends with a ; that does not have to physically be on the same "line" as the rest of the part of a statement this is a potentially important consideration depending on exactly how you intend to use the resultiing information.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have single Input statements that occupy several&amp;nbsp; 100 lines of code because they look liike&lt;/P&gt;
&lt;PRE&gt;input
   var1 $
   var2 
   var3
...
   var240
;
&lt;/PRE&gt;
&lt;P&gt;So what would the line "length" be for something like that?&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jun 2020 14:18:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-get-max-line-length-from-multiple-sas-files/m-p/665799#M199127</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-06-29T14:18:23Z</dc:date>
    </item>
    <item>
      <title>Re: how to get max line length from multiple .sas files?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-get-max-line-length-from-multiple-sas-files/m-p/665803#M199128</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/192091"&gt;@ger15xxhcker&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you very much! It works, only the file names are blank in the end table for some reason. What can cause this?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Try marking FILENAME to be retained by adding a RETAIN statement (or adding it to the exist RETAIN statement).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;At the point where you output a record because you have started a new file you want the value of FNAME from the observation before the one where the name changes, so you need to retain it in the separate variable FILENAME.&amp;nbsp; Note that the variable used in the FILENAME= option of the INFILE statement will not be included in the output dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that by default the length value will be truncated at 32767.&amp;nbsp; If you see files with that value then add the LRECL= option to the INFILE statement. But in that case you can no longer test the _INFILE_ automatic variable to see where the last non-blank character is on the line.&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jun 2020 14:35:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-get-max-line-length-from-multiple-sas-files/m-p/665803#M199128</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-06-29T14:35:10Z</dc:date>
    </item>
  </channel>
</rss>

