<?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: how come it keeps on return 'YES'? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-come-it-keeps-on-return-YES/m-p/294301#M61389</link>
    <description>its my typo, my original is:&lt;BR /&gt;&lt;BR /&gt;if index(x,'WARNING') &amp;gt; 0 then do; %let found='YES'; end</description>
    <pubDate>Fri, 26 Aug 2016 08:28:04 GMT</pubDate>
    <dc:creator>Olime</dc:creator>
    <dc:date>2016-08-26T08:28:04Z</dc:date>
    <item>
      <title>how come it keeps on return 'YES'?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-come-it-keeps-on-return-YES/m-p/294293#M61383</link>
      <description>&lt;P&gt;Hi all, I am new to SAS and now writing a sas code to determine if 'WARNING' was found inside the tmp.log. However, it keeps on return 'YES'. I don't really get that. Please kindly give advice below questions.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Question 1)&lt;/P&gt;&lt;P&gt;%let found='NO';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;infile '/folders/myfolders/myprograms/tmp.log' dlm=' ' truncover;&lt;BR /&gt;input x $1025.;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;if index(x,'WARNING')&amp;lt; 0 then do; %let found='YES'; end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;if &amp;amp;found.=YES then put 'OK...I HAVE FOUND';&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;tmp.log:&lt;/P&gt;&lt;P&gt;hello&lt;/P&gt;&lt;P&gt;hello&lt;/P&gt;&lt;P&gt;hello&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Question 2)&amp;nbsp;&lt;/P&gt;&lt;P&gt;Whats different between&lt;/P&gt;&lt;P&gt;%let found = 'YES' &amp;nbsp;and&lt;/P&gt;&lt;P&gt;%let found = YES&lt;/P&gt;&lt;P&gt;&amp;nbsp;&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;</description>
      <pubDate>Fri, 26 Aug 2016 07:39:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-come-it-keeps-on-return-YES/m-p/294293#M61383</guid>
      <dc:creator>Olime</dc:creator>
      <dc:date>2016-08-26T07:39:35Z</dc:date>
    </item>
    <item>
      <title>Re: how come it keeps on return 'YES'?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-come-it-keeps-on-return-YES/m-p/294296#M61385</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let found='NO';

data _null_;
infile '/folders/myfolders/myprograms/tmp.log' dlm=' ' truncover;
input x $1025.;
if index(x,'WARNING')&amp;lt; 0 then do; %let found='YES'; end;
run;

data _null_;
if &amp;amp;found.=YES then put 'OK...I HAVE FOUND';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The most important thing:&lt;/P&gt;
&lt;P&gt;The macro language is a pre-processing language designed to create dynamic program code.&lt;/P&gt;
&lt;P&gt;Therefore, everytime a macro trigger (&amp;amp; or %) is encountered, the macro processor is envoked, does its thing, and then comes back with or without program text for the main SAS interpreter.&lt;/P&gt;
&lt;P&gt;This means that your %let found='YES'; is &lt;U&gt;immediately&lt;/U&gt; dealt with when program text is collected for the data step compiler, setting found to 'YES'. No program text is generated, so the data step looks like that:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
infile '/folders/myfolders/myprograms/tmp.log' dlm=' ' truncover;
input x $1025.;
if index(x,'WARNING')&amp;lt; 0 then do; end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want to set a macro variable from the &lt;U&gt;execution&lt;/U&gt; of the data step, use call symput().&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The answer to question two: &amp;amp;found will just contain text, once with and once without quotes. Take care if quotes are appropriate/necessary where you use &amp;amp;found.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A much nicer version of writing your checker would be&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
retain signal 0;
infile '/folders/myfolders/myprograms/tmp.log' truncover end=done;
input x $1025.;
if index(x,'WARNING') &amp;gt; 0 then signal = 1;
if done and signal then put 'YES';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;OTOH, I would use grep on the OS level for this. But I'm just an old UNIXer.&lt;/P&gt;</description>
      <pubDate>Fri, 26 Aug 2016 08:14:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-come-it-keeps-on-return-YES/m-p/294296#M61385</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-08-26T08:14:35Z</dc:date>
    </item>
    <item>
      <title>Re: how come it keeps on return 'YES'?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-come-it-keeps-on-return-YES/m-p/294297#M61386</link>
      <description>&lt;P&gt;1.&lt;/P&gt;&lt;P&gt;I think it should be GREATER THAN SYMBOL&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;if index(x,'WARNING') &amp;gt; 0&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let found='NO';
 
data _null_;
infile '/folders/myfolders/myprograms/tmp.log' dlm=' ' truncover;
input x $1025.;

if index(x,'WARNING') &amp;gt;  0 then do; 
CALL SYMPUTX('FOUND','YES');
 end;
run;
 
data _null_;
if &amp;amp;found.=YES then put 'OK...I HAVE FOUND';
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;%let found = 'YES' &amp;nbsp; and &amp;nbsp;%let found = YES has difference.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;first one will have quotes around YES. Second one would not have quotes around YES&lt;/P&gt;</description>
      <pubDate>Fri, 26 Aug 2016 08:09:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-come-it-keeps-on-return-YES/m-p/294297#M61386</guid>
      <dc:creator>RahulG</dc:creator>
      <dc:date>2016-08-26T08:09:07Z</dc:date>
    </item>
    <item>
      <title>Re: how come it keeps on return 'YES'?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-come-it-keeps-on-return-YES/m-p/294298#M61387</link>
      <description>&lt;P&gt;change line:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;SPAN&gt;if index(x,'WARNING') &lt;STRONG&gt;&amp;lt;&lt;/STRONG&gt; 0 then do; %let found='YES'; end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;to:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;&lt;SPAN&gt;if index(x,'WARNING') &lt;STRONG&gt;&amp;gt;&lt;/STRONG&gt; 0 then do; %let found='YES'; end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The INDEX function returns the position of starting string. That can be 0 or &lt;STRONG&gt;positive&lt;/STRONG&gt; only.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;If the string is not found the INDEX will be 0 (zero);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Aug 2016 08:11:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-come-it-keeps-on-return-YES/m-p/294298#M61387</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2016-08-26T08:11:52Z</dc:date>
    </item>
    <item>
      <title>Re: how come it keeps on return 'YES'?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-come-it-keeps-on-return-YES/m-p/294300#M61388</link>
      <description>&lt;PRE&gt;
It could be simple as :


data _null_;
infile '/folders/myfolders/myprograms/tmp.log' ;
input ;
if x =: 'WARNING' then do; putlog 'FOUND:';  putlog _infile_; end;
run;

&lt;/PRE&gt;</description>
      <pubDate>Fri, 26 Aug 2016 08:25:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-come-it-keeps-on-return-YES/m-p/294300#M61388</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-08-26T08:25:20Z</dc:date>
    </item>
    <item>
      <title>Re: how come it keeps on return 'YES'?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-come-it-keeps-on-return-YES/m-p/294301#M61389</link>
      <description>its my typo, my original is:&lt;BR /&gt;&lt;BR /&gt;if index(x,'WARNING') &amp;gt; 0 then do; %let found='YES'; end</description>
      <pubDate>Fri, 26 Aug 2016 08:28:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-come-it-keeps-on-return-YES/m-p/294301#M61389</guid>
      <dc:creator>Olime</dc:creator>
      <dc:date>2016-08-26T08:28:04Z</dc:date>
    </item>
    <item>
      <title>Re: how come it keeps on return 'YES'?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-come-it-keeps-on-return-YES/m-p/294304#M61391</link>
      <description>&lt;P&gt;OOPS! the others are right:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;%LET is a declarative statment that cannot be a part of IF / WHEN / any insteam data step code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sorry for the misinform&lt;/P&gt;</description>
      <pubDate>Fri, 26 Aug 2016 08:38:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-come-it-keeps-on-return-YES/m-p/294304#M61391</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2016-08-26T08:38:21Z</dc:date>
    </item>
    <item>
      <title>Re: how come it keeps on return 'YES'?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-come-it-keeps-on-return-YES/m-p/294307#M61392</link>
      <description>&lt;PRE&gt;
Opps.CODE NOT TESTED


data _null_;
infile '/folders/myfolders/myprograms/tmp.log' end=last;
input ;
retain found 0;
if _infile_ =: 'WARNING' then do; putlog 'FOUND:';  putlog _infile_; found=1; end;
if last and not found then putlog 'OK';
run;


&lt;/PRE&gt;</description>
      <pubDate>Fri, 26 Aug 2016 08:49:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-come-it-keeps-on-return-YES/m-p/294307#M61392</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-08-26T08:49:27Z</dc:date>
    </item>
    <item>
      <title>Re: how come it keeps on return 'YES'?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-come-it-keeps-on-return-YES/m-p/294308#M61393</link>
      <description>&lt;PRE&gt;
Opps.CODE NOT TESTED


data _null_;
infile '/folders/myfolders/myprograms/tmp.log' end=last;
input ;
retain found 0;
if _infile_ =: 'WARNING' then do; putlog 'FOUND:';  putlog _infile_; found=1; end;
if last and not found then putlog 'OK';
run;


&lt;/PRE&gt;</description>
      <pubDate>Fri, 26 Aug 2016 08:49:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-come-it-keeps-on-return-YES/m-p/294308#M61393</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-08-26T08:49:51Z</dc:date>
    </item>
  </channel>
</rss>

