<?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 then efficiency / options in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/if-then-efficiency-options/m-p/256271#M49081</link>
    <description>What I ser from a data management perspective is still lot of hard coded logic. I would favour a lookup table with substr of segment and product type. Use that with a join or a format.&lt;BR /&gt;Another performance killer is I/O. Use s code for product type instead. Required less space,  and makes it easier to rename in the future. &lt;BR /&gt;Are you going to use you flags for calculation? If so set the length to 3. Else char 1.</description>
    <pubDate>Sat, 12 Mar 2016 07:44:42 GMT</pubDate>
    <dc:creator>LinusH</dc:creator>
    <dc:date>2016-03-12T07:44:42Z</dc:date>
    <item>
      <title>if then efficiency / options</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-then-efficiency-options/m-p/256260#M49077</link>
      <description>&lt;P&gt;I have the code below, it works fine but with a larger dataset it will be innefficient.&amp;nbsp; If anyone can help get the same results, I want to do something if else/then but am not sure how to do it with the multiple filters.&amp;nbsp; The segment_id and product_type will change each line, but I only care about the one per line.&amp;nbsp; The selection should account for the entire population.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;_0005 = missing(segment_id);&lt;BR /&gt;if substr(segment_id,1,2) in ('01','02','03','04','05') then do;&lt;BR /&gt;_0006 = 0;else _0006 = 1;&lt;BR /&gt;if substr(segment_id,1,2) = '01' and product_type = 'Secured-Revolving' then&lt;BR /&gt;_0007 = 1;else _0007 = 1;&lt;BR /&gt;if substr(segment_id,1,2) = '02' and product_type = 'Secured-Installment' then&lt;BR /&gt;_0008 = 0;else _0008 = 1;&lt;BR /&gt;if substr(segment_id,1,2) = '03' and product_type = 'Unsecured-Revolving' then&lt;BR /&gt;_0009 = 0;else _0009 = 1;&lt;BR /&gt;if substr(segment_id,1,2) = '04' and product_type = 'Unsecured-Installment' then&lt;BR /&gt;_0010 = 0;else _0010 = 1;&lt;BR /&gt;if substr(segment_id,1,2) = '05' and product_type = 'Overdraft' then&lt;BR /&gt;_0011 = 0;else _0011 = 1;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Mar 2016 23:55:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-then-efficiency-options/m-p/256260#M49077</guid>
      <dc:creator>Steelers_In_DC</dc:creator>
      <dc:date>2016-03-11T23:55:07Z</dc:date>
    </item>
    <item>
      <title>Re: if then efficiency / options</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-then-efficiency-options/m-p/256263#M49078</link>
      <description>&lt;P&gt;Your biggest cost here isn't the IF/THEN logic. &amp;nbsp;It's the repeated use of SUBSTR. &amp;nbsp;You would do much better along these lines:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;length newvar $ 2;&lt;/P&gt;
&lt;P&gt;newvar = substr;&lt;/P&gt;
&lt;P&gt;drop newvar;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;_0005 = missing(segment_id);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;if newvar&amp;nbsp;in ('01','02','03','04','05') then do;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;_0006 = 0;else _0006 = 1;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;if newvar = '01' and product_type = 'Secured-Revolving' then&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;_0007 = 1;else _0007 = 1;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;if newvar = '02' and product_type = 'Secured-Installment' then&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;_0008 = 0;else _0008 = 1;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;if newvar = '03' and product_type = 'Unsecured-Revolving' then&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;_0009 = 0;else _0009 = 1;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;if newvar = '04' and product_type = 'Unsecured-Installment' then&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;_0010 = 0;else _0010 = 1;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;if newvar = '05' and product_type = 'Overdraft' then&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;_0011 = 0;else _0011 = 1;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;end;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;else _0006 = 1;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I'm not sure if I got all the assignments right for all the flags, but this would definitely improve the speed.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Good luck.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 12 Mar 2016 03:19:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-then-efficiency-options/m-p/256263#M49078</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-03-12T03:19:41Z</dc:date>
    </item>
    <item>
      <title>Re: if then efficiency / options</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-then-efficiency-options/m-p/256271#M49081</link>
      <description>What I ser from a data management perspective is still lot of hard coded logic. I would favour a lookup table with substr of segment and product type. Use that with a join or a format.&lt;BR /&gt;Another performance killer is I/O. Use s code for product type instead. Required less space,  and makes it easier to rename in the future. &lt;BR /&gt;Are you going to use you flags for calculation? If so set the length to 3. Else char 1.</description>
      <pubDate>Sat, 12 Mar 2016 07:44:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-then-efficiency-options/m-p/256271#M49081</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2016-03-12T07:44:42Z</dc:date>
    </item>
    <item>
      <title>Re: if then efficiency / options</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-then-efficiency-options/m-p/256328#M49112</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;_0005 = missing(segment_id);
_0006 = 0; /* Might not be necessary since Missing and 0 are both FALSE */
select (substr(segment_id, 1, 2));
	when ("01") _0007 = not (product_type = 'Secured-Revolving');
	when ("02") _0008 = not (product_type = 'Secured-Installment');
	when ("03") _0009 = not (product_type = 'Unsecured-Revolving');
	when ("04") _0010 = not (product_type = 'Unsecured-Installment');
	when ("05") _0011 = not (product_type = 'Overdraft');
	otherwise _0006 = 1;
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(untested)&lt;/P&gt;</description>
      <pubDate>Sat, 12 Mar 2016 20:20:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-then-efficiency-options/m-p/256328#M49112</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-03-12T20:20:25Z</dc:date>
    </item>
  </channel>
</rss>

