<?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: Determine the logical record length of a text file in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Determine-the-logical-record-length-of-a-text-file/m-p/678739#M204904</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
 infile 'c:\temp\have.csv' end=last;
 input;
 retain lrecl ;
 lrecl=max(lrecl,length(_infile_));
 if last then putlog 'max lrecl is ' lrecl;
 run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;NOTE: The infile 'c:\temp\have.csv' is:
      File Name=c:\temp\have.csv,
      RECFM=V,LRECL=256

max lrecl is 74
NOTE: 148 records were read from the infile 'c:\temp\have.csv'.
      The minimum record length was 0.
      The maximum record length was 74.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds

&lt;/PRE&gt;</description>
    <pubDate>Sun, 23 Aug 2020 12:14:19 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2020-08-23T12:14:19Z</dc:date>
    <item>
      <title>Determine the logical record length of a text file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determine-the-logical-record-length-of-a-text-file/m-p/678736#M204902</link>
      <description>&lt;P&gt;Dear community members,&lt;/P&gt;
&lt;P&gt;Hope you are healthy and feeling well these days.&lt;/P&gt;
&lt;P&gt;I am not a programmer, so please forgive me for my unprofessional language. This is my problem:&lt;/P&gt;
&lt;P&gt;I import into SAS a text file with no delimiters; variables are defined by fixed spaces. I am now getting this file in an old version (LRECL=316) and a new version (LRECL=322) with some changes in certain fields. I need to differentiate between the two based on this difference alone. Is there a function in SAS or SAS/SQL that will return the LRECL of a text file?&lt;/P&gt;
&lt;P&gt;TIA,&lt;/P&gt;
&lt;P&gt;Michael&lt;/P&gt;</description>
      <pubDate>Sun, 23 Aug 2020 11:54:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determine-the-logical-record-length-of-a-text-file/m-p/678736#M204902</guid>
      <dc:creator>MichaelvanStraten</dc:creator>
      <dc:date>2020-08-23T11:54:57Z</dc:date>
    </item>
    <item>
      <title>Re: Determine the logical record length of a text file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determine-the-logical-record-length-of-a-text-file/m-p/678738#M204903</link>
      <description>&lt;P&gt;Do this first:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
infile "yourfile" lrecl=350 length=rlen obs=1;
input;
call symputx('rlen',rlen);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This will store the observed length of the first line into &amp;amp;rlen, so you can run the following code conditionally.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PS if you read the file with RECFM=F or RECFM=N, which means that no line separators are present in the file, you will need a more complicated trick.&lt;/P&gt;</description>
      <pubDate>Sun, 23 Aug 2020 12:14:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determine-the-logical-record-length-of-a-text-file/m-p/678738#M204903</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-08-23T12:14:42Z</dc:date>
    </item>
    <item>
      <title>Re: Determine the logical record length of a text file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determine-the-logical-record-length-of-a-text-file/m-p/678739#M204904</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
 infile 'c:\temp\have.csv' end=last;
 input;
 retain lrecl ;
 lrecl=max(lrecl,length(_infile_));
 if last then putlog 'max lrecl is ' lrecl;
 run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;NOTE: The infile 'c:\temp\have.csv' is:
      File Name=c:\temp\have.csv,
      RECFM=V,LRECL=256

max lrecl is 74
NOTE: 148 records were read from the infile 'c:\temp\have.csv'.
      The minimum record length was 0.
      The maximum record length was 74.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds

&lt;/PRE&gt;</description>
      <pubDate>Sun, 23 Aug 2020 12:14:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determine-the-logical-record-length-of-a-text-file/m-p/678739#M204904</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-08-23T12:14:19Z</dc:date>
    </item>
    <item>
      <title>Re: Determine the logical record length of a text file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determine-the-logical-record-length-of-a-text-file/m-p/678740#M204905</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Text file with fixed record layout and also HAS line termination characters&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Use&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;example utilizing INFILE LENGTH=&amp;lt;variable&amp;gt; option to retrieve data record length from 1st line of file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Text file with fixed record layout and has NO line termination characters&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;The MOD function can be useful&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Determine filesize&lt;/LI&gt;
&lt;LI&gt;Compute
&lt;UL&gt;
&lt;LI&gt;R1 = mod (filesize,316)&lt;/LI&gt;
&lt;LI&gt;R2 = mod (filesize,322)&lt;/LI&gt;
&lt;/UL&gt;
&lt;/LI&gt;
&lt;LI&gt;if R1 = 0 and R2 ^= 0 presume record length 316; else&lt;BR /&gt;if&amp;nbsp;R1 ^= 0 and R2 = 0 presume record length 322; else&lt;BR /&gt;filesize is k x LCM(316,322).&amp;nbsp;&amp;nbsp;Perform test inputs and your understanding of expected values to determine which record length (i.e. record type) you have.&lt;BR /&gt;&lt;EM&gt;Note: LCM(316,322) is filesize 32,232&lt;/EM&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Example code for determining file size (in Windows)&lt;/P&gt;
&lt;PRE&gt;filename au 'autoexec.sas';

data _null_;
  fid = fopen ('au');

  filesize = finfo(fid,'file size (bytes)');
  put 'NOTE: ' filesize=;

  rc = fclose (fid);
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 23 Aug 2020 13:09:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determine-the-logical-record-length-of-a-text-file/m-p/678740#M204905</guid>
      <dc:creator>RichardDeVen</dc:creator>
      <dc:date>2020-08-23T13:09:55Z</dc:date>
    </item>
    <item>
      <title>Re: Determine the logical record length of a text file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determine-the-logical-record-length-of-a-text-file/m-p/678741#M204906</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12477"&gt;@RichardDeVen&lt;/a&gt;'s method is the "trick" I was referring to in my PS.&lt;/P&gt;</description>
      <pubDate>Sun, 23 Aug 2020 12:16:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determine-the-logical-record-length-of-a-text-file/m-p/678741#M204906</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-08-23T12:16:34Z</dc:date>
    </item>
    <item>
      <title>Re: Determine the logical record length of a text file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determine-the-logical-record-length-of-a-text-file/m-p/678747#M204910</link>
      <description>&lt;P&gt;Dear KurtBremser, Ksharp and RichardADeVenezia,&lt;/P&gt;
&lt;P&gt;Thank you all for your helpful solutions.&lt;/P&gt;
&lt;P&gt;Michael&lt;/P&gt;</description>
      <pubDate>Sun, 23 Aug 2020 13:07:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determine-the-logical-record-length-of-a-text-file/m-p/678747#M204910</guid>
      <dc:creator>MichaelvanStraten</dc:creator>
      <dc:date>2020-08-23T13:07:06Z</dc:date>
    </item>
  </channel>
</rss>

