<?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: File Length of Binary File in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/File-Length-of-Binary-File/m-p/260502#M50555</link>
    <description>&lt;P&gt;Here's a variation on your DATA step that should speed it up somewhat:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data _null_;&lt;BR /&gt;infile "&amp;amp;dspath.&amp;amp;dsname." recfm=n end=done;&lt;BR /&gt;input a $char1.;&lt;BR /&gt;if done then call symputx ('file_len', _n_);&lt;BR /&gt;run;&lt;/P&gt;</description>
    <pubDate>Thu, 31 Mar 2016 18:23:33 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2016-03-31T18:23:33Z</dc:date>
    <item>
      <title>File Length of Binary File</title>
      <link>https://communities.sas.com/t5/SAS-Programming/File-Length-of-Binary-File/m-p/260494#M50553</link>
      <description>&lt;P&gt;I need to find the file length of a binary file to use in calculating the number of records in the file. &amp;nbsp;I found a way to get the file length but it takes an extra Data step and finding the file length takes longer than reading the file. &amp;nbsp;(Most likely do to my poor codeing.)&lt;/P&gt;&lt;P&gt;The data step below works, but like I said it's slow.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;infile "&amp;amp;dspath.&amp;amp;dsname." recfm=n;&lt;BR /&gt;input a $char1.;&lt;BR /&gt;i+1;&lt;BR /&gt;call symput('file_len',trim(left(i)));&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks Vince&lt;/P&gt;</description>
      <pubDate>Thu, 31 Mar 2016 18:09:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/File-Length-of-Binary-File/m-p/260494#M50553</guid>
      <dc:creator>VinceH</dc:creator>
      <dc:date>2016-03-31T18:09:30Z</dc:date>
    </item>
    <item>
      <title>Re: File Length of Binary File</title>
      <link>https://communities.sas.com/t5/SAS-Programming/File-Length-of-Binary-File/m-p/260502#M50555</link>
      <description>&lt;P&gt;Here's a variation on your DATA step that should speed it up somewhat:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data _null_;&lt;BR /&gt;infile "&amp;amp;dspath.&amp;amp;dsname." recfm=n end=done;&lt;BR /&gt;input a $char1.;&lt;BR /&gt;if done then call symputx ('file_len', _n_);&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Mar 2016 18:23:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/File-Length-of-Binary-File/m-p/260502#M50555</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-03-31T18:23:33Z</dc:date>
    </item>
    <item>
      <title>Re: File Length of Binary File</title>
      <link>https://communities.sas.com/t5/SAS-Programming/File-Length-of-Binary-File/m-p/260504#M50557</link>
      <description>&lt;P&gt;I think I tried this. "END" can not be used for unbuffered reads and when you add "recfm=n" for a binary file it's unbuffered. &amp;nbsp;So I think "done" never becomes TRUE.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Vince&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Mar 2016 18:27:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/File-Length-of-Binary-File/m-p/260504#M50557</guid>
      <dc:creator>VinceH</dc:creator>
      <dc:date>2016-03-31T18:27:54Z</dc:date>
    </item>
    <item>
      <title>Re: File Length of Binary File</title>
      <link>https://communities.sas.com/t5/SAS-Programming/File-Length-of-Binary-File/m-p/260507#M50558</link>
      <description>&lt;P&gt;Where there's a will there's a way.&amp;nbsp; Let's try it this way:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data _null_;&lt;BR /&gt;infile "&amp;amp;dspath.&amp;amp;dsname." recfm=n eof=done;&lt;BR /&gt;input a $char1.;&lt;/P&gt;
&lt;P&gt;return;&lt;/P&gt;
&lt;P&gt;done:&amp;nbsp; call symputx ('file_len', _n_);&lt;/P&gt;
&lt;P&gt;stop;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But make sure that _N_ is the right value to use.&amp;nbsp; It might conceivably be _n_ - 1, depending on when the EOF logic kicks in.&amp;nbsp; If that's a problem, you can always go back to your original idea:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data _null_;&lt;BR /&gt;infile "&amp;amp;dspath.&amp;amp;dsname." recfm=n eof=done;&lt;BR /&gt;input a $char1.;&lt;/P&gt;
&lt;P&gt;i + 1;&lt;/P&gt;
&lt;P&gt;return;&lt;/P&gt;
&lt;P&gt;done:&amp;nbsp; call symputx ('file_len', i);&lt;/P&gt;
&lt;P&gt;stop;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Mar 2016 18:38:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/File-Length-of-Binary-File/m-p/260507#M50558</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-03-31T18:38:05Z</dc:date>
    </item>
    <item>
      <title>Re: File Length of Binary File</title>
      <link>https://communities.sas.com/t5/SAS-Programming/File-Length-of-Binary-File/m-p/260516#M50562</link>
      <description>&lt;P&gt;Walking the entire file seems like a waist of resources. Why not use the finfo function?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Eg.&lt;/P&gt;
&lt;PRE class="xis-codeFragment"&gt;data fileatt;
   length name $ 20 value $ 40;
   drop fid j infonum;
   filename myfile "&amp;amp;dspath.&amp;amp;dsname.";
   fid=fopen("myfile");
   infonum=foptnum(fid);
   do j=1 to infonum;
      name=foptname(fid, j);
      value=finfo(fid, name);
      put 'File attribute' name 'has a value of ' value;
      output;
   end;
run;&lt;/PRE&gt;
&lt;P&gt;Have a look at the doc to get to filesize directly plus OS specifics.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps,&lt;/P&gt;
&lt;P&gt;- Jan.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;EDIT: In case of UTF-8 or other multibyte encoding the size in characters does not always equal the size in bytes.&lt;/P&gt;</description>
      <pubDate>Thu, 31 Mar 2016 19:12:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/File-Length-of-Binary-File/m-p/260516#M50562</guid>
      <dc:creator>jklaverstijn</dc:creator>
      <dc:date>2016-03-31T19:12:25Z</dc:date>
    </item>
    <item>
      <title>Re: File Length of Binary File</title>
      <link>https://communities.sas.com/t5/SAS-Programming/File-Length-of-Binary-File/m-p/260536#M50571</link>
      <description>&lt;P&gt;Excelent, this is just waht I was after. &amp;nbsp;My code is now:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;filename myfile "&amp;amp;dspath.&amp;amp;dsname.";&lt;BR /&gt;fid=fopen("myfile");&lt;BR /&gt;call symput('file_len',finfo(fid, 'File Size (bytes)'));&lt;BR /&gt;run;&lt;BR /&gt;%put &amp;amp;file_len;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It runs instantly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Vince&lt;/P&gt;</description>
      <pubDate>Thu, 31 Mar 2016 20:02:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/File-Length-of-Binary-File/m-p/260536#M50571</guid>
      <dc:creator>VinceH</dc:creator>
      <dc:date>2016-03-31T20:02:34Z</dc:date>
    </item>
  </channel>
</rss>

