<?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 Different Results Flag in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Different-Results-Flag/m-p/619946#M182105</link>
    <description>&lt;P&gt;&lt;STRONG&gt;Would someone be able to explain what is the difference in terms of the sas data step processing with the flaf&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;I get different results with the same dataset&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data NAC_D_6; set NAC_D_5;

array op[10] Main_Problem OTHER_PROBLEM_1 - OTHER_PROBLEM_9;

array opp[10] MAIN_PROBLEM_PREFIX OTHER_PROBLEM_PREFIX_1 - OTHER_PROBLEM_PREFIX_9;



flag_stroke_q=1;



do i=1 to 10;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if substr(op[i],1,3) in: ('I63' 'I64' 'H341') and opp[i]~='Q' and substr(op[i],1,4)~='I636'

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; then flag_stroke_q=0;

end;

drop i;

if flag_stroke_q=0;



run;

data NAC_D_6; set NAC_D_5;
array op[10] Main_Problem OTHER_PROBLEM_1 - OTHER_PROBLEM_9;
array opp[10] MAIN_PROBLEM_PREFIX OTHER_PROBLEM_PREFIX_1 - OTHER_PROBLEM_PREFIX_9;

flag_stroke_q=0;

do i=1 to 10;
	if substr(op[i],1,3) in: ('I63' 'I64' 'H341') and opp[i]='Q' and substr(op[i],1,4)~='I636'
	then flag_stroke_q+1;
end;
drop i;
if flag_stroke_q=0;

run;*



&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; NAC_D_6; set NAC_D_5;&lt;/P&gt;&lt;P&gt;array op[&lt;STRONG&gt;10&lt;/STRONG&gt;] Main_Problem OTHER_PROBLEM_1 - OTHER_PROBLEM_9;&lt;/P&gt;&lt;P&gt;array opp[&lt;STRONG&gt;10&lt;/STRONG&gt;] MAIN_PROBLEM_PREFIX OTHER_PROBLEM_PREFIX_1 - OTHER_PROBLEM_PREFIX_9;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;flag_stroke_q=&lt;STRONG&gt;0&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;do i=&lt;STRONG&gt;1&lt;/STRONG&gt; to &lt;STRONG&gt;10&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if substr(op[i],&lt;STRONG&gt;1&lt;/STRONG&gt;,&lt;STRONG&gt;3&lt;/STRONG&gt;) in: ('I63' 'I64' 'H341') and opp[i]='Q' and substr(op[i],&lt;STRONG&gt;1&lt;/STRONG&gt;,&lt;STRONG&gt;4&lt;/STRONG&gt;)~='I636'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; then flag_stroke_q+&lt;STRONG&gt;1&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;drop i;&lt;/P&gt;&lt;P&gt;if flag_stroke_q=&lt;STRONG&gt;0&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;*&lt;/P&gt;</description>
    <pubDate>Fri, 24 Jan 2020 23:24:08 GMT</pubDate>
    <dc:creator>Ranjeeta</dc:creator>
    <dc:date>2020-01-24T23:24:08Z</dc:date>
    <item>
      <title>Different Results Flag</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Different-Results-Flag/m-p/619946#M182105</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Would someone be able to explain what is the difference in terms of the sas data step processing with the flaf&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;I get different results with the same dataset&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data NAC_D_6; set NAC_D_5;

array op[10] Main_Problem OTHER_PROBLEM_1 - OTHER_PROBLEM_9;

array opp[10] MAIN_PROBLEM_PREFIX OTHER_PROBLEM_PREFIX_1 - OTHER_PROBLEM_PREFIX_9;



flag_stroke_q=1;



do i=1 to 10;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if substr(op[i],1,3) in: ('I63' 'I64' 'H341') and opp[i]~='Q' and substr(op[i],1,4)~='I636'

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; then flag_stroke_q=0;

end;

drop i;

if flag_stroke_q=0;



run;

data NAC_D_6; set NAC_D_5;
array op[10] Main_Problem OTHER_PROBLEM_1 - OTHER_PROBLEM_9;
array opp[10] MAIN_PROBLEM_PREFIX OTHER_PROBLEM_PREFIX_1 - OTHER_PROBLEM_PREFIX_9;

flag_stroke_q=0;

do i=1 to 10;
	if substr(op[i],1,3) in: ('I63' 'I64' 'H341') and opp[i]='Q' and substr(op[i],1,4)~='I636'
	then flag_stroke_q+1;
end;
drop i;
if flag_stroke_q=0;

run;*



&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; NAC_D_6; set NAC_D_5;&lt;/P&gt;&lt;P&gt;array op[&lt;STRONG&gt;10&lt;/STRONG&gt;] Main_Problem OTHER_PROBLEM_1 - OTHER_PROBLEM_9;&lt;/P&gt;&lt;P&gt;array opp[&lt;STRONG&gt;10&lt;/STRONG&gt;] MAIN_PROBLEM_PREFIX OTHER_PROBLEM_PREFIX_1 - OTHER_PROBLEM_PREFIX_9;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;flag_stroke_q=&lt;STRONG&gt;0&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;do i=&lt;STRONG&gt;1&lt;/STRONG&gt; to &lt;STRONG&gt;10&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if substr(op[i],&lt;STRONG&gt;1&lt;/STRONG&gt;,&lt;STRONG&gt;3&lt;/STRONG&gt;) in: ('I63' 'I64' 'H341') and opp[i]='Q' and substr(op[i],&lt;STRONG&gt;1&lt;/STRONG&gt;,&lt;STRONG&gt;4&lt;/STRONG&gt;)~='I636'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; then flag_stroke_q+&lt;STRONG&gt;1&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;drop i;&lt;/P&gt;&lt;P&gt;if flag_stroke_q=&lt;STRONG&gt;0&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;*&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jan 2020 23:24:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Different-Results-Flag/m-p/619946#M182105</guid>
      <dc:creator>Ranjeeta</dc:creator>
      <dc:date>2020-01-24T23:24:08Z</dc:date>
    </item>
    <item>
      <title>Re: Different Results Flag</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Different-Results-Flag/m-p/619956#M182107</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/240770"&gt;@Ranjeeta&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;STRONG&gt;Would someone be able to explain what is the difference in terms of the sas data step processing with the flaf&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;I get different results with the same dataset&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data NAC_D_6; set NAC_D_5;

array op[10] Main_Problem OTHER_PROBLEM_1 - OTHER_PROBLEM_9;

array opp[10] MAIN_PROBLEM_PREFIX OTHER_PROBLEM_PREFIX_1 - OTHER_PROBLEM_PREFIX_9;



flag_stroke_q=1;



do i=1 to 10;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if substr(op[i],1,3) in: ('I63' 'I64' 'H341') and opp[i]~='Q' and substr(op[i],1,4)~='I636'

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; then flag_stroke_q=0;

end;

drop i;

if flag_stroke_q=0;



run;

data NAC_D_6; set NAC_D_5;
array op[10] Main_Problem OTHER_PROBLEM_1 - OTHER_PROBLEM_9;
array opp[10] MAIN_PROBLEM_PREFIX OTHER_PROBLEM_PREFIX_1 - OTHER_PROBLEM_PREFIX_9;

flag_stroke_q=0;

do i=1 to 10;
	if substr(op[i],1,3) in: ('I63' 'I64' 'H341') and opp[i]='Q' and substr(op[i],1,4)~='I636'
	then flag_stroke_q+1;
end;
drop i;
if flag_stroke_q=0;

run;*



&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; NAC_D_6; set NAC_D_5;&lt;/P&gt;
&lt;P&gt;array op[&lt;STRONG&gt;10&lt;/STRONG&gt;] Main_Problem OTHER_PROBLEM_1 - OTHER_PROBLEM_9;&lt;/P&gt;
&lt;P&gt;array opp[&lt;STRONG&gt;10&lt;/STRONG&gt;] MAIN_PROBLEM_PREFIX OTHER_PROBLEM_PREFIX_1 - OTHER_PROBLEM_PREFIX_9;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;flag_stroke_q=&lt;STRONG&gt;0&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;do i=&lt;STRONG&gt;1&lt;/STRONG&gt; to &lt;STRONG&gt;10&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if substr(op[i],&lt;STRONG&gt;1&lt;/STRONG&gt;,&lt;STRONG&gt;3&lt;/STRONG&gt;) in: ('I63' 'I64' 'H341') and opp[i]='Q' and substr(op[i],&lt;STRONG&gt;1&lt;/STRONG&gt;,&lt;STRONG&gt;4&lt;/STRONG&gt;)~='I636'&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; then flag_stroke_q+&lt;STRONG&gt;1&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;drop i;&lt;/P&gt;
&lt;P&gt;if flag_stroke_q=&lt;STRONG&gt;0&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;*&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;When you use the code structure:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;then flag_stroke_q+1;
&lt;/PRE&gt;
&lt;P&gt;Then you have told SAS the value of the &amp;nbsp;variable FLAG_STROKE_Q is to be retained across observatation so you should be careful with that structure.&lt;/P&gt;
&lt;P&gt;Here's an example of that feature:&lt;/P&gt;
&lt;PRE&gt;data example;
   set sashelp.class;
   flag+1;
run;&lt;/PRE&gt;
&lt;P&gt;Not an issue because you initialize the variable in each iteration, but be careful.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You start with a different value for your Flag variable before the DO loop in both cases, one only&amp;nbsp; has the option of changing the flag to 0 and the other adds to the value of the each time a comparison is true.. So you create different values for the variable and then only keep the records when 0.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The first code would only have the record at least one of the conditions in the loop is true.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The second will keep the record only if ALL of the records have the comparisons as false.&lt;/P&gt;</description>
      <pubDate>Sat, 25 Jan 2020 00:02:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Different-Results-Flag/m-p/619956#M182107</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-01-25T00:02:11Z</dc:date>
    </item>
    <item>
      <title>Re: Different Results Flag</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Different-Results-Flag/m-p/620001#M182117</link>
      <description>&lt;P&gt;Well, you ran two different programs against the same data.&amp;nbsp; Is it a shock that the results are different?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try removing this statement from both programs:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if flag_stroke_q=0;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then you can look at the final values for FLAG_STROKE and see if they make sense to you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;On a side note, both programs get the wrong answer.&amp;nbsp; SUBSTR and IN: are usually a bad mix.&amp;nbsp; Remove the SUBSTR function.&amp;nbsp; Otherwise, you will process "H34" instead of "H341".&lt;/P&gt;</description>
      <pubDate>Sat, 25 Jan 2020 15:16:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Different-Results-Flag/m-p/620001#M182117</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2020-01-25T15:16:46Z</dc:date>
    </item>
  </channel>
</rss>

