<?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: if statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/if-statement/m-p/802408#M315874</link>
    <description>&lt;P&gt;You are using two different types of IF statements there.&lt;/P&gt;
&lt;P&gt;First is the IF/THEN/ELSE form.&lt;/P&gt;
&lt;P&gt;Second is the subsetting IF form.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the condition in a subsetting IF is TRUE then the data step iteration continues to the rest of the statements in the step.&amp;nbsp; But if it is FALSE then the data step stops the current iteration.&amp;nbsp; Which means that the rest of the statements in the data step are skipped and control goes back to the start of the data step.&amp;nbsp; In your code that means the SET statement executes again and the next observation is processed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That is the same thing that happens when you execute the DELETE statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So your subsetting IF statement:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if samp_ex=" ";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Is the same thing as this IF/THEN statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if not (samp_ex=" ") then delete;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So none of the observations where EXCLUDE was set to Y by the IF/THEN/ELSE series of statements will be written to the new version of the SAMP dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 16 Mar 2022 02:39:52 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2022-03-16T02:39:52Z</dc:date>
    <item>
      <title>if statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-statement/m-p/802400#M315870</link>
      <description>&lt;PRE&gt;data samp;
set samp;
if samp_ex="" then exclude='N';
else exclude='Y';
if samp_ex="";
run;&lt;/PRE&gt;
&lt;P&gt;can you let me know if the statement "if samp_ex="": means the data step only runs if samp_ex="" is true, ie samp_ex is null is true...&lt;/P&gt;
&lt;P&gt;is the data step the same if this if statement "if samp_ex" is place directly under "set samp;"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am confused because:&lt;/P&gt;
&lt;P&gt;1. I was thinking the statement after "if samp_ex="" " only runs when&amp;nbsp;"if samp_ex="" is true. the statement after it is "run", does that mean the whole data step only runs when&amp;nbsp;"if samp_ex="" is true, ie the statement&amp;nbsp;if samp_ex="" then exclude='N'; else exclude='Y'; wouldnt run either if samp_ex is not null?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;or&amp;nbsp;if samp_ex="" then exclude='N'; else exclude='Y'; runs anyway as it is before "if sam_Ex-"""&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2, I was told the "if samp_ex=""" or a where statement could be put anywhere in the data step and the data step only runs if the if statement is true or the where condition is fulfilled...&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;please kindly assist, thanks.&lt;/P&gt;
&lt;P&gt;also&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Mar 2022 01:36:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-statement/m-p/802400#M315870</guid>
      <dc:creator>HeatherNewton</dc:creator>
      <dc:date>2022-03-16T01:36:51Z</dc:date>
    </item>
    <item>
      <title>Re: if statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-statement/m-p/802408#M315874</link>
      <description>&lt;P&gt;You are using two different types of IF statements there.&lt;/P&gt;
&lt;P&gt;First is the IF/THEN/ELSE form.&lt;/P&gt;
&lt;P&gt;Second is the subsetting IF form.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the condition in a subsetting IF is TRUE then the data step iteration continues to the rest of the statements in the step.&amp;nbsp; But if it is FALSE then the data step stops the current iteration.&amp;nbsp; Which means that the rest of the statements in the data step are skipped and control goes back to the start of the data step.&amp;nbsp; In your code that means the SET statement executes again and the next observation is processed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That is the same thing that happens when you execute the DELETE statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So your subsetting IF statement:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if samp_ex=" ";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Is the same thing as this IF/THEN statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if not (samp_ex=" ") then delete;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So none of the observations where EXCLUDE was set to Y by the IF/THEN/ELSE series of statements will be written to the new version of the SAMP dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Mar 2022 02:39:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-statement/m-p/802408#M315874</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-03-16T02:39:52Z</dc:date>
    </item>
    <item>
      <title>Re: if statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-statement/m-p/802422#M315887</link>
      <description>&lt;P&gt;Your code is equivalent to this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data samp;
set samp;
where samp_ex="";
exclude='N';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Since only observations that meet the condition will make it, there is no need to create EXCLUDE conditionally.&lt;/P&gt;
&lt;P&gt;And since the subsetting IF is wholly dependent on variables from the incoming dataset, a WHERE is clearer to understand and performs better.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Mar 2022 06:30:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-statement/m-p/802422#M315887</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-03-16T06:30:26Z</dc:date>
    </item>
  </channel>
</rss>

