<?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: which method is faster optimize code in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/which-method-is-faster-optimize-code/m-p/820890#M324052</link>
    <description>&lt;P&gt;This is likely faster:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data wh15;
  set sashelp.class;
  where age=15;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This is because the WHERE statement exports the filtering to the data engine.&amp;nbsp; Unlike your two alternatives, the data step never sees the unwanted observations, so never needs to populate the program data vector with them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Of course you will need a lot larger dataset than sashelp.class to find any difference.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also if you are doing a test of input speed, don't contaminate the test with (implied) output operations.&amp;nbsp; Use &lt;EM&gt;&lt;STRONG&gt;data _null_&lt;/STRONG&gt;&lt;/EM&gt;, as in:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
do until(age=15);
set sashelp.class;
end;
run;


data _null_;
set sashelp.class;
if age=15 then output;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 29 Jun 2022 11:27:45 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2022-06-29T11:27:45Z</dc:date>
    <item>
      <title>which method is faster optimize code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/which-method-is-faster-optimize-code/m-p/820880#M324047</link>
      <description>&lt;PRE&gt;&lt;CODE class=""&gt;options stimer;

data du;
do until(age=15);
set sashelp.class;
end;
run;


data ifst;
set sashelp.class;
if age=15 then output;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 29 Jun 2022 09:56:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/which-method-is-faster-optimize-code/m-p/820880#M324047</guid>
      <dc:creator>Suryak</dc:creator>
      <dc:date>2022-06-29T09:56:47Z</dc:date>
    </item>
    <item>
      <title>Re: which method is faster optimize code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/which-method-is-faster-optimize-code/m-p/820890#M324052</link>
      <description>&lt;P&gt;This is likely faster:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data wh15;
  set sashelp.class;
  where age=15;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This is because the WHERE statement exports the filtering to the data engine.&amp;nbsp; Unlike your two alternatives, the data step never sees the unwanted observations, so never needs to populate the program data vector with them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Of course you will need a lot larger dataset than sashelp.class to find any difference.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also if you are doing a test of input speed, don't contaminate the test with (implied) output operations.&amp;nbsp; Use &lt;EM&gt;&lt;STRONG&gt;data _null_&lt;/STRONG&gt;&lt;/EM&gt;, as in:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
do until(age=15);
set sashelp.class;
end;
run;


data _null_;
set sashelp.class;
if age=15 then output;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 29 Jun 2022 11:27:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/which-method-is-faster-optimize-code/m-p/820890#M324052</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-06-29T11:27:45Z</dc:date>
    </item>
    <item>
      <title>Re: which method is faster optimize code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/which-method-is-faster-optimize-code/m-p/820967#M324080</link>
      <description>&lt;P&gt;INCORRECT STATETENTS&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#999999"&gt;Also note that both steps are not equivalent:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#999999"&gt;If age=15 &lt;STRONG&gt;doesn't exist&lt;/STRONG&gt; in sashelp.class,&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#999999"&gt;dataset du will contain the last observation of sashelp.class &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#999999"&gt;but dataset ifst will be empty.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#999999"&gt;If age=15 occurs &lt;STRONG&gt;more than once&lt;/STRONG&gt; in sashelp.class,&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#999999"&gt;dataset du will contain the first such observation&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#999999"&gt;but dataset ifst will contain all of them.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;EDIT: See &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/19879"&gt;@Quentin&lt;/a&gt;'s comment below. My statements above were INCORRECT. I should have tested. Sorry.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jun 2022 19:04:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/which-method-is-faster-optimize-code/m-p/820967#M324080</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2022-06-29T19:04:52Z</dc:date>
    </item>
    <item>
      <title>Re: which method is faster optimize code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/which-method-is-faster-optimize-code/m-p/820995#M324098</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462"&gt;@PGStats&lt;/a&gt;&amp;nbsp;, they looks equivalent to me.&amp;nbsp; I don't think either of your statements about what happens if age=15 doesn't exist, or if there are multiple records with age=15, are correct.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;1
2    data du;
3    do until(age=99);
4    set sashelp.class;
5    end;
6    run;

NOTE: There were 19 observations read from the data set SASHELP.CLASS.
NOTE: The data set WORK.DU has 0 observations and 5 variables.
NOTE: DATA statement used (Total process time):
      real time           0.04 seconds
      cpu time            0.00 seconds


7
8
9    data ifst;
10   set sashelp.class;
11   if age=99 then output;
12   run;

NOTE: There were 19 observations read from the data set SASHELP.CLASS.
NOTE: The data set WORK.IFST has 0 observations and 5 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


13
14
15   data du;
16   do until(age=15);
17   set sashelp.class;
18   end;
19   run;

NOTE: There were 19 observations read from the data set SASHELP.CLASS.
NOTE: The data set WORK.DU has 4 observations and 5 variables.
NOTE: Compressing data set WORK.DU increased size by 100.00 percent.
      Compressed is 2 pages; un-compressed would require 1 pages.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


20
21
22   data ifst;
23   set sashelp.class;
24   if age=15 then output;
25   run;

NOTE: There were 19 observations read from the data set SASHELP.CLASS.
NOTE: The data set WORK.IFST has 4 observations and 5 variables.
NOTE: Compressing data set WORK.IFST increased size by 100.00 percent.
      Compressed is 2 pages; un-compressed would require 1 pages.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jun 2022 18:17:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/which-method-is-faster-optimize-code/m-p/820995#M324098</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2022-06-29T18:17:20Z</dc:date>
    </item>
    <item>
      <title>Re: which method is faster optimize code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/which-method-is-faster-optimize-code/m-p/821012#M324110</link>
      <description>&lt;P&gt;There might be a little extra overhead to setup the DO loop, but really both are reading the same observations and performing the same comparison of AGE to the constant 15.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is probably going to be even better to use a WHERE statement, especially if your source dataset is some remote database since then SAS will not even transfer the other observations from the database to SAS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Which one to use is based on WHY you are doing it and what the rest of the data step is actually doing.&lt;/P&gt;
&lt;P&gt;You probably want to use the version that makes understanding, creating, validating, and maintaining the code the easiest.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jun 2022 19:45:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/which-method-is-faster-optimize-code/m-p/821012#M324110</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-06-29T19:45:25Z</dc:date>
    </item>
    <item>
      <title>Re: which method is faster optimize code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/which-method-is-faster-optimize-code/m-p/821056#M324139</link>
      <description>&lt;P&gt;In my experience, if you are doing simple, sequential DATA step reads, experimenting with DO loops is a waste of time - stick with just a SET statement as adding DO's will have minimal impact on performance. If you want to optimize your code focus on other areas, especially any really slow processes.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jun 2022 03:01:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/which-method-is-faster-optimize-code/m-p/821056#M324139</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2022-06-30T03:01:31Z</dc:date>
    </item>
  </channel>
</rss>

