<?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: Input statement retain file data as rows with the detail in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Input-statement-retain-file-data-as-rows-with-the-detail/m-p/780853#M248847</link>
    <description>Awesome thanks Tom</description>
    <pubDate>Wed, 17 Nov 2021 19:58:20 GMT</pubDate>
    <dc:creator>jimbobob</dc:creator>
    <dc:date>2021-11-17T19:58:20Z</dc:date>
    <item>
      <title>Input statement retain file data as rows with the detail</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Input-statement-retain-file-data-as-rows-with-the-detail/m-p/780802#M248815</link>
      <description>&lt;P&gt;I have text files that are pipe delimited with no header, but has a header row that contains file date and some other fields followed by detail, followed by Trailer Record looks like this:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SampleData.JPG" style="width: 654px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/65843i3442E3E1C3F83C8D/image-size/large?v=v2&amp;amp;px=999" role="button" title="SampleData.JPG" alt="SampleData.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;I want to retain the header record down thru the detail. I get close but instead of retaining the word HEADER throughout the data my first variable in my detail is getting split at 6 characters:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ouput.JPG" style="width: 750px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/65845i9E87B186BA410A8C/image-size/large?v=v2&amp;amp;px=999" role="button" title="Ouput.JPG" alt="Ouput.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;This is the logic I was using:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA WORK.SM_DB_NF_20211116;

	INFILE 'Y:\File Transfers\I2C\Incoming\SM_DB_NF_20211116.TXT'
 	LRECL=32767
 	FIRSTOBS=1
 	ENCODING="WLATIN1"
 	DLM='7c'x
 	MISSOVER
 	DSD;

	FORMAT

        F1               $CHAR6.
        F2               $CHAR3.
        F3               $CHAR13.
        F4               MMDDYY10.
        F5               MMDDYY10.
        F6               MMDDYY10.
        F7               BEST1. 
 	CARD_NUMBER	$CHAR19.
 	OPEN_DATE	DATE9.
 	EXPIRATION_DATE	MMDDYY10.
... more fields;

	RETAIN F1 F2 F3 F4 F5 F6 F7;
	input F1 $6. @;

	if F1 = "HEADER" then do;
	    INPUT
	        F1               : $CHAR6.
	        F2               : $CHAR3.
	        F3               : $CHAR13.
	        F4               : ?? MMDDYY8.
	        F5               : ?? MMDDYY8.
	        F6               : ?? MMDDYY8.
	        F7               : ?? BEST1. ;
	end;
	else do;
		INPUT
		 	CARD_NUMBER	: $CHAR19. 
		 	OPEN_DATE : ?? ANYDTDTE8.
		 	EXPIRATION_DATE	: ?? MMDDYY8.
		 	... more fields;
	end;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Any help would be appreciated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Nov 2021 17:51:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Input-statement-retain-file-data-as-rows-with-the-detail/m-p/780802#M248815</guid>
      <dc:creator>jimbobob</dc:creator>
      <dc:date>2021-11-17T17:51:03Z</dc:date>
    </item>
    <item>
      <title>Re: Input statement retain file data as rows with the detail</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Input-statement-retain-file-data-as-rows-with-the-detail/m-p/780819#M248825</link>
      <description>&lt;P&gt;To do something special on the first row just test the value of the automatic variable _N_.&lt;/P&gt;
&lt;P&gt;Note: Use the LENGTH statement to DEFINE your variables.&amp;nbsp; FORMAT is for attaching instructions for how to print the values.&amp;nbsp; In your data it looks like you only need that for the variables that have DATE values. Normal numbers and character variables do not need to have any format attached to them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA WORK.SM_DB_NF_20211116;
  INFILE 'Y:\File Transfers\I2C\Incoming\SM_DB_NF_20211116.TXT'
    ENCODING="WLATIN1"
    DSD DLM='|'
    TRUNCOVER
  ;

  LENGTH
      F1               $6
      F2               $3
      F3               $13
      F4               8
      F5               8
      F6               8
      F7               8
      CARD_NUMBER      $19
      OPEN_DATE        8
      EXPIRATION_DATE  8
... more fields
  ;

  FORMAT
      F4               MMDDYY10.
      F5               MMDDYY10.
      F6               MMDDYY10.
      OPEN_DATE DATE9.
      EXPIRATION_DATE MMDDYY10.
... more fields that REQUIRE formats attached ...
  ;

  INFORMAT
      F4               MMDDYY.
      F5               MMDDYY.
      F6               MMDDYY.
      OPEN_DATE        ANYDTDTE.
      EXPIRATION_DATE  MMDDYY.
... more fields that REQUIRE informats to be read correctly ...
  ;

  RETAIN F1 F2 F3 F4 F5 F6 F7;
  if _n_=1 then input F1-F7;
  INPUT
    CARD_NUMBER 
    OPEN_DATE ?? 
    EXPIRATION_DATE  ?? 
... more fields
  ;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 Nov 2021 19:30:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Input-statement-retain-file-data-as-rows-with-the-detail/m-p/780819#M248825</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-11-17T19:30:28Z</dc:date>
    </item>
    <item>
      <title>Re: Input statement retain file data as rows with the detail</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Input-statement-retain-file-data-as-rows-with-the-detail/m-p/780853#M248847</link>
      <description>Awesome thanks Tom</description>
      <pubDate>Wed, 17 Nov 2021 19:58:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Input-statement-retain-file-data-as-rows-with-the-detail/m-p/780853#M248847</guid>
      <dc:creator>jimbobob</dc:creator>
      <dc:date>2021-11-17T19:58:20Z</dc:date>
    </item>
    <item>
      <title>Re: Input statement retain file data as rows with the detail</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Input-statement-retain-file-data-as-rows-with-the-detail/m-p/780857#M248850</link>
      <description>&lt;P&gt;You can also use the END= option on the INFILE statement to set a variable you can use to detect when you have reached the end of the file.&amp;nbsp; To get it set before you try to read the line add and extra INPUT with trailing&amp;nbsp;@.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;...
  infile .... end=eof .... ;
...
  input @;
  if eof then do;
     put _infile_;
     if _infile_ ne: 'TRAILER' then put 'ERROR: Trailer record is missing.';
     else stop;     
  end;
  if _n_=1 then ...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Nov 2021 20:05:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Input-statement-retain-file-data-as-rows-with-the-detail/m-p/780857#M248850</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-11-17T20:05:20Z</dc:date>
    </item>
  </channel>
</rss>

