<?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: Difference between IF and WHERE statements in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Difference-between-IF-and-WHERE-statements/m-p/338369#M77043</link>
    <description>&lt;P&gt;Lets assume that&amp;nbsp;&lt;SPAN&gt;city is some variable that you yourself have calculated further uo in your datastep. Then example 1 will not work, since city does not exist in the dataset in your set statement. Example 2 however will work, since this is a subsetting if statement.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 06 Mar 2017 07:51:01 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2017-03-06T07:51:01Z</dc:date>
    <item>
      <title>Difference between IF and WHERE statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-between-IF-and-WHERE-statements/m-p/338361#M77039</link>
      <description>&lt;P&gt;i want know, what is the difference&amp;nbsp;between these two programs.&lt;/P&gt;&lt;P&gt;1. data c;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set a;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; where city = "london";&lt;/P&gt;&lt;P&gt;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;2. data c;&lt;/P&gt;&lt;P&gt;set a;&lt;/P&gt;&lt;P&gt;if city = "london";&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Mar 2017 07:09:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-between-IF-and-WHERE-statements/m-p/338361#M77039</guid>
      <dc:creator>Ishwarkumar</dc:creator>
      <dc:date>2017-03-06T07:09:18Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between IF and WHERE statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-between-IF-and-WHERE-statements/m-p/338362#M77040</link>
      <description>&lt;P&gt;In your example I would use option 1 as it can utilize&amp;nbsp;an index on the city variable in dataset a (if such an index exists and would be beneficial). There are several articles on the differences between where and if and with&amp;nbsp;more complex scenarios.&amp;nbsp;A nice short one to get you started is&amp;nbsp;&lt;A href="http://support.sas.com/kb/24/286.html" target="_self"&gt;SAS&amp;nbsp;Usage Note 24286: When do I use a WHERE statement instead of an IF statement to subset a data set?&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Personally I use where where I can and if if I have to &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Mar 2017 07:22:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-between-IF-and-WHERE-statements/m-p/338362#M77040</guid>
      <dc:creator>PaulHomes</dc:creator>
      <dc:date>2017-03-06T07:22:28Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between IF and WHERE statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-between-IF-and-WHERE-statements/m-p/338363#M77041</link>
      <description>&lt;P&gt;In example 1 you utilize that dataset a contains the variable city.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You are not sure about that in example 2 where you are using a socalled "subsetting if statement". This means that you reach the implied output and return statements at the end of your datastep if that condition is true &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Mar 2017 07:29:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-between-IF-and-WHERE-statements/m-p/338363#M77041</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2017-03-06T07:29:31Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between IF and WHERE statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-between-IF-and-WHERE-statements/m-p/338367#M77042</link>
      <description>&lt;P&gt;if both the programs are executing. then, why to use both.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Mar 2017 07:45:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-between-IF-and-WHERE-statements/m-p/338367#M77042</guid>
      <dc:creator>Ishwarkumar</dc:creator>
      <dc:date>2017-03-06T07:45:31Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between IF and WHERE statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-between-IF-and-WHERE-statements/m-p/338369#M77043</link>
      <description>&lt;P&gt;Lets assume that&amp;nbsp;&lt;SPAN&gt;city is some variable that you yourself have calculated further uo in your datastep. Then example 1 will not work, since city does not exist in the dataset in your set statement. Example 2 however will work, since this is a subsetting if statement.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Mar 2017 07:51:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-between-IF-and-WHERE-statements/m-p/338369#M77043</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2017-03-06T07:51:01Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between IF and WHERE statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-between-IF-and-WHERE-statements/m-p/338370#M77044</link>
      <description>&lt;P&gt;if we use 'where statement'. then, it we read only one observation (where city = "london";), and if we use 'subsetting if statement'. then, it will read all the observations and gives the result.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Mar 2017 07:58:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-between-IF-and-WHERE-statements/m-p/338370#M77044</guid>
      <dc:creator>Ishwarkumar</dc:creator>
      <dc:date>2017-03-06T07:58:00Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between IF and WHERE statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-between-IF-and-WHERE-statements/m-p/338371#M77045</link>
      <description>&lt;P&gt;If I understand your post correctly, you want to use BOTH the where statement and the subsetting if statement. This is not a good idea.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My rule of thumb:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If the variable city exists in your input dataset: Use where statement&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you created the variable city yourself: Use the Subsetting if statement.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When in doubt: Use the subsetting if statement &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Mar 2017 08:06:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-between-IF-and-WHERE-statements/m-p/338371#M77045</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2017-03-06T08:06:40Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between IF and WHERE statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-between-IF-and-WHERE-statements/m-p/338396#M77054</link>
      <description>&lt;P&gt;A developer shouldn't be in doubt.&amp;nbsp;&lt;img id="manwink" class="emoticon emoticon-manwink" src="https://communities.sas.com/i/smilies/16x16_man-wink.png" alt="Man Wink" title="Man Wink" /&gt;&lt;/P&gt;
&lt;P&gt;WHERE is always preferred&amp;nbsp;because of better performance.&lt;/P&gt;
&lt;P&gt;IF should only be used for subsetting if WHERE isn't possible to use.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Mar 2017 10:14:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-between-IF-and-WHERE-statements/m-p/338396#M77054</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2017-03-06T10:14:29Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between IF and WHERE statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-between-IF-and-WHERE-statements/m-p/338397#M77055</link>
      <description>&lt;P&gt;WHERE-- filter obs before it enter PDV.&lt;/P&gt;
&lt;P&gt;IF -- filter obs after it enter PDV.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Mar 2017 10:16:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-between-IF-and-WHERE-statements/m-p/338397#M77055</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-03-06T10:16:38Z</dc:date>
    </item>
  </channel>
</rss>

