<?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: where vs. if in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/where-vs-if/m-p/711433#M219166</link>
    <description>&lt;P&gt;When SAS reads the row of a data into PDV, two variables will be created i.e. the FIRST.variable and LAST.variable.&lt;BR /&gt;These variables are not in the input table . Therefore, you can't use the WHERE statement to subset rows of variables which are not yet&lt;BR /&gt;in the input data. Instead, you can use the subsetting IF statement.&lt;/P&gt;</description>
    <pubDate>Thu, 14 Jan 2021 12:42:45 GMT</pubDate>
    <dc:creator>hak18</dc:creator>
    <dc:date>2021-01-14T12:42:45Z</dc:date>
    <item>
      <title>where vs. if</title>
      <link>https://communities.sas.com/t5/SAS-Programming/where-vs-if/m-p/490670#M128436</link>
      <description>&lt;P&gt;I know that where can be used in both DATA and PROC step, whereas if can only be used in DATA step. However, w&lt;SPAN&gt;hat is the difference between where and if?&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Aug 2018 23:27:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/where-vs-if/m-p/490670#M128436</guid>
      <dc:creator>clq</dc:creator>
      <dc:date>2018-08-28T23:27:33Z</dc:date>
    </item>
    <item>
      <title>Re: where vs. if</title>
      <link>https://communities.sas.com/t5/SAS-Programming/where-vs-if/m-p/490675#M128438</link>
      <description>&lt;P&gt;&lt;FONT size="4"&gt;The where statement&amp;nbsp;can be used in procedures to subset data.&amp;nbsp; The if statement cannot be used in procedures.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="4"&gt;The where statement is more efficient than the if statement&lt;STRONG&gt;.&lt;/STRONG&gt; It tells SAS not to read all observations from the data set.&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Aug 2018 23:37:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/where-vs-if/m-p/490675#M128438</guid>
      <dc:creator>VDD</dc:creator>
      <dc:date>2018-08-28T23:37:29Z</dc:date>
    </item>
    <item>
      <title>Re: where vs. if</title>
      <link>https://communities.sas.com/t5/SAS-Programming/where-vs-if/m-p/490689#M128446</link>
      <description>&lt;P&gt;&lt;A href="http://www2.sas.com/proceedings/sugi31/238-31.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/sugi31/238-31.pdf&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And many, many more:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://www.lexjansen.com/search/searchresults.php?q=where%20vs%20if" target="_blank"&gt;https://www.lexjansen.com/search/searchresults.php?q=where%20vs%20if&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/228427"&gt;@clq&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I know that where can be used in both DATA and PROC step, whereas if can only be used in DATA step. However, w&lt;SPAN&gt;hat is the difference between where and if?&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Aug 2018 00:59:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/where-vs-if/m-p/490689#M128446</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-08-29T00:59:29Z</dc:date>
    </item>
    <item>
      <title>Re: where vs. if</title>
      <link>https://communities.sas.com/t5/SAS-Programming/where-vs-if/m-p/490697#M128450</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/122002"&gt;@VDD&lt;/a&gt;&amp;nbsp;&lt;EM&gt;The where statement is more efficient than the if statement&lt;STRONG&gt;.&lt;/STRONG&gt;&amp;nbsp;It tells SAS not to read all observations from the data set.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Not always.&amp;nbsp;When functions are used, IF is faster than WHERE.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This has to do&amp;nbsp;with functions being optimised to&amp;nbsp;access PDV data,&amp;nbsp;but not so fast when reading from the read buffer.&lt;/P&gt;
&lt;P&gt;If someone has more details I'd be curious to know more actually.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;So&amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;FONT face="courier new,courier"&gt;if A=1;&amp;nbsp;&lt;/FONT&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;is slower than&lt;/SPAN&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;where A=1;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;But&amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;FONT face="courier new,courier"&gt;if round(A)=1;&amp;nbsp;&lt;/FONT&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;is faster than&lt;/SPAN&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;where round(A)=1;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data TEST;
  do I=1 to 1e8;
    output;
  end;
run;
   
sasfile TEST load;
                                    
data _null_; set TEST; if          I =0; run;  *  4 seconds;
data _null_; set TEST; where       I =0; run;  *  2 seconds;
data _null_; set TEST; if    round(I)=0; run;  *  5 seconds;
data _null_; set TEST; where round(I)=0; run;  * 11 seconds;

sasfile TEST close;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Aug 2018 02:33:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/where-vs-if/m-p/490697#M128450</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-08-29T02:33:39Z</dc:date>
    </item>
    <item>
      <title>Re: where vs. if</title>
      <link>https://communities.sas.com/t5/SAS-Programming/where-vs-if/m-p/490733#M128479</link>
      <description>&lt;P&gt;Also, if you have multiple datasets coming in (merge), a where statement may not be possible:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data sexes;
set sashelp.class;
keep name sex;
run;

data others;
set sashelp.class (drop=sex);
run;

data want;
merge
  others
  sexes
;
by name;
where age = 16;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;but the if will work:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
merge
  others
  sexes
;
by name;
if age = 16;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you need to build a combined condition using variables from multiple datasets that are not present in all, then the subsetting if statement is the only option.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Aug 2018 06:27:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/where-vs-if/m-p/490733#M128479</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-08-29T06:27:40Z</dc:date>
    </item>
    <item>
      <title>Re: where vs. if</title>
      <link>https://communities.sas.com/t5/SAS-Programming/where-vs-if/m-p/490938#M128614</link>
      <description>&lt;P&gt;WHERE statements or data set option can only reference variables that appear in the incoming data set(s), If can use newly created variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example: The first data step generates an error, the second doesn't.&lt;/P&gt;
&lt;PRE&gt;data junk;
   set sashelp.class;
   ns= catt(name,sex);
   where ns in ('AlfredM' 'CarolF');
run;

data junk2;
   set sashelp.class;
   ns= catt(name,sex);
   if ns in ('AlfredM' 'CarolF');
run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 29 Aug 2018 18:05:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/where-vs-if/m-p/490938#M128614</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-08-29T18:05:08Z</dc:date>
    </item>
    <item>
      <title>Re: where vs. if</title>
      <link>https://communities.sas.com/t5/SAS-Programming/where-vs-if/m-p/711433#M219166</link>
      <description>&lt;P&gt;When SAS reads the row of a data into PDV, two variables will be created i.e. the FIRST.variable and LAST.variable.&lt;BR /&gt;These variables are not in the input table . Therefore, you can't use the WHERE statement to subset rows of variables which are not yet&lt;BR /&gt;in the input data. Instead, you can use the subsetting IF statement.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jan 2021 12:42:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/where-vs-if/m-p/711433#M219166</guid>
      <dc:creator>hak18</dc:creator>
      <dc:date>2021-01-14T12:42:45Z</dc:date>
    </item>
  </channel>
</rss>

