<?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: Reading header and trailer data from text file in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Reading-header-and-trailer-data-from-text-file/m-p/506758#M135845</link>
    <description>&lt;UL&gt;
&lt;LI&gt;you don't need to shout at us or the SAS interpreter&lt;/LI&gt;
&lt;LI&gt;post code in a code posting window, or it gets mangled&lt;/LI&gt;
&lt;LI&gt;use indentation to create easily readable code&lt;/LI&gt;
&lt;LI&gt;use a row hold (@) after reading the record type&lt;/LI&gt;
&lt;LI&gt;no informats needed for simple numbers&lt;/LI&gt;
&lt;LI&gt;no positions needed when reading delimited files&lt;/LI&gt;
&lt;LI&gt;instead of "if-then-else if" use a select() block&lt;/LI&gt;
&lt;LI&gt;use the proper date informat on input&lt;/LI&gt;
&lt;LI&gt;assign a proper date format for readability&lt;/LI&gt;
&lt;/UL&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
infile cards dlm="|" dsd;
input record_type @;
select (record_type);
  when (0)do; 
    cnt_hdr + 1;
    output;
  end;
  when (9) do;
    input
      process_name :$4.
      load_date :ddmmyy10.
      number_of_records
    ;
    cnt_tlr + 1;
    output;
  end;
  otherwise do;
    input
      system :$4.
      environment :$4.
      portfolio :$3.
      subportfolio :$2.
    ;
    tot_cnt + 1;
    output;
  end;
end;
format load_date ddmmyy10.;
cards;
0|FILE|ENV|p1|p2
1|CARD|PROD|GER|SW
1|CARD|DEV|GER|SW
1|CARD|PROD|GER|VP
9||22/10/2018|3
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 23 Oct 2018 09:40:38 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2018-10-23T09:40:38Z</dc:date>
    <item>
      <title>Reading header and trailer data from text file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-header-and-trailer-data-from-text-file/m-p/506754#M135841</link>
      <description>&lt;P&gt;I have a input text file which has data in the below format:&amp;nbsp;&lt;/P&gt;&lt;P&gt;0|FILE|ENV|p1|p2&lt;/P&gt;&lt;P&gt;1|CARD|PROD|GER|SW&lt;BR /&gt;1|CARD|DEV|GER|SW&lt;BR /&gt;1|CARD|PROD|GER|VP&lt;BR /&gt;9||22/10/2018|3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The record with 0 is header, 1 is the information and 9 is footer. I used the below code to read this file but it does not read the data correctly. I need to read the trailer for the information and use them but can drop header and trailer variables at the end. Could you please help:&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA TEST;&lt;BR /&gt;INFILE File1 DLM="|" DSD ;&lt;/P&gt;&lt;P&gt;INPUT @1 RECORD_TYPE 1.;&lt;/P&gt;&lt;P&gt;IF RECORD_TYPE = 0 THEN DO;&lt;BR /&gt;CNT_HDR +1;&lt;BR /&gt;OUTPUT;&lt;BR /&gt;END;&lt;/P&gt;&lt;P&gt;ELSE IF RECORD_TYPE=9 THEN DO;&lt;BR /&gt;INPUT PROCESS_NAME :$4.&lt;BR /&gt;LOAD_DATE :DATE9.&lt;BR /&gt;NUMBER_OF_RECORDS :1.;&lt;BR /&gt;&lt;BR /&gt;CNT_TLR+1;&lt;BR /&gt;OUTPUT;&lt;BR /&gt;&lt;BR /&gt;END;&lt;/P&gt;&lt;P&gt;ELSE DO;&lt;BR /&gt;INPUT @2 SYSTEM :$4.&lt;BR /&gt;ENVIRONMENT :$4.&lt;BR /&gt;PORTFOLIO :$3.&lt;BR /&gt;SUBPORTFOLIO :$2.&lt;BR /&gt;TOT_CNT+1;&lt;BR /&gt;OUTPUT;&lt;BR /&gt;END;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Oct 2018 09:11:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-header-and-trailer-data-from-text-file/m-p/506754#M135841</guid>
      <dc:creator>Jagadeesh2907</dc:creator>
      <dc:date>2018-10-23T09:11:09Z</dc:date>
    </item>
    <item>
      <title>Re: Reading header and trailer data from text file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-header-and-trailer-data-from-text-file/m-p/506756#M135843</link>
      <description>&lt;P&gt;Just read in the file as a pipe delimited file, then you will have a variable where you can do conditional logic to see if its 0 or 9?&amp;nbsp; I can't actually read that code as its all in upper case, doesn't use a code window (its the {i} above post area), and has smileys in it and such like.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Oct 2018 09:32:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-header-and-trailer-data-from-text-file/m-p/506756#M135843</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-10-23T09:32:56Z</dc:date>
    </item>
    <item>
      <title>Re: Reading header and trailer data from text file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-header-and-trailer-data-from-text-file/m-p/506758#M135845</link>
      <description>&lt;UL&gt;
&lt;LI&gt;you don't need to shout at us or the SAS interpreter&lt;/LI&gt;
&lt;LI&gt;post code in a code posting window, or it gets mangled&lt;/LI&gt;
&lt;LI&gt;use indentation to create easily readable code&lt;/LI&gt;
&lt;LI&gt;use a row hold (@) after reading the record type&lt;/LI&gt;
&lt;LI&gt;no informats needed for simple numbers&lt;/LI&gt;
&lt;LI&gt;no positions needed when reading delimited files&lt;/LI&gt;
&lt;LI&gt;instead of "if-then-else if" use a select() block&lt;/LI&gt;
&lt;LI&gt;use the proper date informat on input&lt;/LI&gt;
&lt;LI&gt;assign a proper date format for readability&lt;/LI&gt;
&lt;/UL&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
infile cards dlm="|" dsd;
input record_type @;
select (record_type);
  when (0)do; 
    cnt_hdr + 1;
    output;
  end;
  when (9) do;
    input
      process_name :$4.
      load_date :ddmmyy10.
      number_of_records
    ;
    cnt_tlr + 1;
    output;
  end;
  otherwise do;
    input
      system :$4.
      environment :$4.
      portfolio :$3.
      subportfolio :$2.
    ;
    tot_cnt + 1;
    output;
  end;
end;
format load_date ddmmyy10.;
cards;
0|FILE|ENV|p1|p2
1|CARD|PROD|GER|SW
1|CARD|DEV|GER|SW
1|CARD|PROD|GER|VP
9||22/10/2018|3
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 23 Oct 2018 09:40:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-header-and-trailer-data-from-text-file/m-p/506758#M135845</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-10-23T09:40:38Z</dc:date>
    </item>
  </channel>
</rss>

