<?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: Finding If Footer Information is present in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Finding-If-Footer-Information-is-present/m-p/427620#M281407</link>
    <description>&lt;P&gt;I agree with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;.&amp;nbsp; One thing I would also add is with regards to the file format.&amp;nbsp; What you have there is a delimited file, so the question is why does it have record count at the end?&amp;nbsp; Record count and other metadata should be part of the documentation associated with the transfer sure, but this should not be in the datafile, as what you have now is a corrupted delimited file.&amp;nbsp; Send it back and tell them to do it properly.&lt;/P&gt;</description>
    <pubDate>Mon, 15 Jan 2018 09:10:04 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2018-01-15T09:10:04Z</dc:date>
    <item>
      <title>Finding If Footer Information is present</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-If-Footer-Information-is-present/m-p/427605#M281404</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to Process a file If footer is present..&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We need to process a file like below.. but with many variables&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;XXXX|TTTTT|HJJHJJK|909090&lt;/P&gt;
&lt;P&gt;XXXX|TTTTT|HJJHJJK|909090&lt;/P&gt;
&lt;P&gt;yyyyk|hdhbhhjpo|jhvjhvj|567884&lt;/P&gt;
&lt;P&gt;yyyyk|hdhbhhjpo|jhvjhvj|567884&lt;/P&gt;
&lt;P&gt;Total Number Of Recs:4&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please check the code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro a;
 
data _null_;
infile "&amp;amp;Dfile" firstobs=1 end=eof
dsd missover lrecl=3000;
length input_rec $1024;
input input_rec $;
if eof then 
call symputx('footer', input_rec);
run;
%put &amp;amp;footer;
%let substring=Total number;
%let match =%index(%upcase(&amp;amp;footer),%upcase(&amp;amp;substring));
%if &amp;amp;match %then
%put Footer Exists;
%else 
%put Footer does not Exist;
 
%mend;
%a&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here The footer can be anything like TTL NO REC:4&lt;/P&gt;
&lt;P&gt;So I should not be hardcoding the footer sub string..&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there any Other Approach?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit by KurtBremser: moved the code from attachment to code window&lt;/P&gt;
&lt;P&gt;It's not necessary to use an attached file for codes of considerably short length; use the proper sub-windows for that ("little running man", {i})&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jan 2018 06:50:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-If-Footer-Information-is-present/m-p/427605#M281404</guid>
      <dc:creator>sfffdg</dc:creator>
      <dc:date>2018-01-15T06:50:59Z</dc:date>
    </item>
    <item>
      <title>Re: Finding If Footer Information is present</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-If-Footer-Information-is-present/m-p/427609#M281405</link>
      <description>Like with all situations when solving problems with programming you need to come up with a rule, that could be string matching, absence of a delimiter or something else.</description>
      <pubDate>Mon, 15 Jan 2018 07:08:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-If-Footer-Information-is-present/m-p/427609#M281405</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2018-01-15T07:08:05Z</dc:date>
    </item>
    <item>
      <title>Re: Finding If Footer Information is present</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-If-Footer-Information-is-present/m-p/427611#M281406</link>
      <description>&lt;P&gt;You can do it without macro coding in data steps:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let match=0;
%let dlm=|;

data _null_;
infile "&amp;amp;Dfile." firstobs=1 end=eof dsd missover lrecl=3000 dlm="&amp;amp;dlm.";
input
  var1
  var2
  var3
  var4
;
if eof then do;
  if indexc(_infile_,"&amp;amp;dlm.") = 0 then call symput('match','1');
end;
run;

data _null_;
if &amp;amp;match
then put 'Footer present';
else put 'No footer present';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that the code uses the presence of the delimiter to recognize a possoble footer line.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to avoid reading the whole file, you could use a commandline tool to retrieve the last line:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename oscmd pipe "tail -1 &amp;amp;Dfile.";

data _null_;
infile oscmd;
input;
if indexc(_infile_,"&amp;amp;dlm.") &amp;gt; 0
then call symput('match','0');
else call symput('match','1');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(for UNIX systems)&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jan 2018 07:27:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-If-Footer-Information-is-present/m-p/427611#M281406</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-01-15T07:27:52Z</dc:date>
    </item>
    <item>
      <title>Re: Finding If Footer Information is present</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-If-Footer-Information-is-present/m-p/427620#M281407</link>
      <description>&lt;P&gt;I agree with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;.&amp;nbsp; One thing I would also add is with regards to the file format.&amp;nbsp; What you have there is a delimited file, so the question is why does it have record count at the end?&amp;nbsp; Record count and other metadata should be part of the documentation associated with the transfer sure, but this should not be in the datafile, as what you have now is a corrupted delimited file.&amp;nbsp; Send it back and tell them to do it properly.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jan 2018 09:10:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-If-Footer-Information-is-present/m-p/427620#M281407</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-01-15T09:10:04Z</dc:date>
    </item>
    <item>
      <title>Re: Finding If Footer Information is present</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-If-Footer-Information-is-present/m-p/427682#M281408</link>
      <description>&lt;P&gt;You have an excellent suggestion from&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;about how to read just the last observation from your file, instead of reading through all of them.&amp;nbsp; However, in case your file is short and you don't care about reading a few extra records, here is how you would work with your existing program to simplify it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Keep it all in your DATA step.&amp;nbsp; It's easy to modify the end of your DATA step in this way.&amp;nbsp; First, move this statement to before the DATA step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let substring=Total number;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then change the end of the DATA step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if eof;&lt;/P&gt;
&lt;P&gt;if index( upcase(input_rec), upcase("&amp;amp;substring") ) then put 'Footer Exists';&lt;/P&gt;
&lt;P&gt;else put 'Footer does not Exist';&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Everything else that follows the DATA step can disappear.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jan 2018 13:42:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-If-Footer-Information-is-present/m-p/427682#M281408</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-01-15T13:42:43Z</dc:date>
    </item>
    <item>
      <title>Re: Finding If Footer Information is present</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-If-Footer-Information-is-present/m-p/427937#M281409</link>
      <description>Thank you sir for an elegant solution!!</description>
      <pubDate>Tue, 16 Jan 2018 07:46:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-If-Footer-Information-is-present/m-p/427937#M281409</guid>
      <dc:creator>sfffdg</dc:creator>
      <dc:date>2018-01-16T07:46:37Z</dc:date>
    </item>
  </channel>
</rss>

