<?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 &amp;quot;Efficient&amp;quot; form for SAS data step in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/quot-Efficient-quot-form-for-SAS-data-step/m-p/279177#M56234</link>
    <description>&lt;P&gt;Some of the websites out there talk of using the "most efficient" form for writing a program. &amp;nbsp;Please take a look at the following:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data SASData__N (keep = Combo_Plus i1_X i2_X Label1 nValue1 Label2 nValue2);
set Moments_Combined (where = (Label1='N'));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I was very glad to simply get the above program to run. &amp;nbsp;Does it look "efficient" enough? &amp;nbsp;Should I attempt to try some other route?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Nicholas Kormanik&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 22 Jun 2016 02:32:59 GMT</pubDate>
    <dc:creator>NKormanik</dc:creator>
    <dc:date>2016-06-22T02:32:59Z</dc:date>
    <item>
      <title>"Efficient" form for SAS data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/quot-Efficient-quot-form-for-SAS-data-step/m-p/279177#M56234</link>
      <description>&lt;P&gt;Some of the websites out there talk of using the "most efficient" form for writing a program. &amp;nbsp;Please take a look at the following:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data SASData__N (keep = Combo_Plus i1_X i2_X Label1 nValue1 Label2 nValue2);
set Moments_Combined (where = (Label1='N'));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I was very glad to simply get the above program to run. &amp;nbsp;Does it look "efficient" enough? &amp;nbsp;Should I attempt to try some other route?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Nicholas Kormanik&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jun 2016 02:32:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/quot-Efficient-quot-form-for-SAS-data-step/m-p/279177#M56234</guid>
      <dc:creator>NKormanik</dc:creator>
      <dc:date>2016-06-22T02:32:59Z</dc:date>
    </item>
    <item>
      <title>Re: "Efficient" form for SAS data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/quot-Efficient-quot-form-for-SAS-data-step/m-p/279187#M56237</link>
      <description>&lt;P&gt;The only efficiency here is adding the WHERE clause to your SET statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The KEEP on the output vs in the datastep doesn't make a difference AFAIK.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PS. Please post your code in a code block to make it easier to read. See the little running man icon on the editor.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jun 2016 02:33:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/quot-Efficient-quot-form-for-SAS-data-step/m-p/279187#M56237</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-06-22T02:33:15Z</dc:date>
    </item>
    <item>
      <title>Re: "Efficient" form for SAS data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/quot-Efficient-quot-form-for-SAS-data-step/m-p/279189#M56238</link>
      <description>&lt;P&gt;Moving KEEP= to the SET statement will make the program run faster:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; SASData__N&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;set&lt;/SPAN&gt; Moments_Combined &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token statement"&gt;where&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;Label1&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'N') keep=Combo_Plus i1_X i2_X Label1 nValue1 Label2 nValue2&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;);&lt;BR /&gt;run;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assuming that there are other variables in the incoming data set, the SET statement no longer has to read in those other variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In most cases, WHERE runs faster than a subsetting IF. &amp;nbsp;The most important factors are the percentage of observations that meet the WHERE condition, and the number of variables in the data set. &amp;nbsp;If most observations have Label1='N', you could try this and compare the speed:&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; SASData__N&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;set&lt;/SPAN&gt; Moments_Combined &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;keep=Combo_Plus i1_X i2_X Label1 nValue1 Label2 nValue2&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;);&lt;BR /&gt;if Label1='N';&lt;BR /&gt;run;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is likely to be slower, but running it is the sure way to find out. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Finally, if your data sets are small, you might not be able to measure which technique is faster. &amp;nbsp;You would probably need a minimum of tens of thousands of observations to notice a difference (possibly more than that).&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jun 2016 02:50:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/quot-Efficient-quot-form-for-SAS-data-step/m-p/279189#M56238</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-06-22T02:50:02Z</dc:date>
    </item>
    <item>
      <title>Re: "Efficient" form for SAS data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/quot-Efficient-quot-form-for-SAS-data-step/m-p/279196#M56240</link>
      <description>&lt;P&gt;Moving Keep to SET only works if you're not calculating new variables which it appears you aren't in this case.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another way to make this faster, if required, may be to use PROC COPY because it doesn't read the data set line by line but can copy it over in blocks. It doesn't look like you're doing any processing in the step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jun 2016 04:20:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/quot-Efficient-quot-form-for-SAS-data-step/m-p/279196#M56240</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-06-22T04:20:06Z</dc:date>
    </item>
    <item>
      <title>Re: "Efficient" form for SAS data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/quot-Efficient-quot-form-for-SAS-data-step/m-p/279198#M56242</link>
      <description>&lt;P&gt;Thank you Astounding and Reeza. &amp;nbsp;So glad I asked, and you were so available. &amp;nbsp;I tried experimenting with other formats, but failed. &amp;nbsp;Great to have the answer.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Nicholas&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jun 2016 04:21:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/quot-Efficient-quot-form-for-SAS-data-step/m-p/279198#M56242</guid>
      <dc:creator>NKormanik</dc:creator>
      <dc:date>2016-06-22T04:21:38Z</dc:date>
    </item>
  </channel>
</rss>

