<?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: Looking for any efficient way. in SAS Viya</title>
    <link>https://communities.sas.com/t5/SAS-Viya/Looking-for-any-efficient-way/m-p/851172#M1591</link>
    <description>&lt;P&gt;Your code shows two types of conditions for month='M+0':&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Simple cutoff:&amp;nbsp; &amp;nbsp;For given product codes, there are specific cutoff values for AMB_OCT_M0.&amp;nbsp; In every case when AMB_OCT_M0 is below the cutoff then PROD_BAL=0, otherwise PROD_BAL=10.&lt;BR /&gt;&lt;BR /&gt;&lt;/LI&gt;
&lt;LI&gt;core_urban cutoff.&amp;nbsp; For given product code in combination with core_urban='Urban', or 'Core', there are specific cutoff values.&amp;nbsp; Again, in every case when AMB_OCT_M0 is below the cutoff then PROD_BAL=0, otherwise PROD_BAL=10.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;You can make a dataset for each of these cutoff structures.&amp;nbsp; Then use those datasets as hash objects, for quick lookup of product code, month, (and core_urban) to retrieve the cutoff value, followed by testing AMB_OCT_MO against that cutoff.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's what the code would look like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA PRODWISE_AMB_CHECK (drop=_:);
  SET BC_UC_ALL(WHERE=(PRODUCT_CODE NOT IN('20101','20102','20103')));

  if _n=1 then do;
    if 0 then set simple_cutoff core_urban_cutoff;
    declare hash s (dataset:'simple_cutoff');
      s.definekey('month','product_code');
      s.definedata(all:'Y');
      s.definedone();
    declare hash cu (dataset:'core_urban_cutoff');
      cu.definekey('month','core_urban','product_code');
      cu.definedata(all:'Y');
      cu.definedone();
  end;
  if s.find()=0  then prod_bal=ifn(amb_oct_m0&amp;lt;_cutoff,_bal_below_cutoff,_bal_not_below_cutoff);   else
  if cu.find()=0 then prod_bal=ifn(amb_oct_m0&amp;lt;_cutoff,_bal_below_cutoff,_bal_not_below_cutoff);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This code must be preceded by creating the two datasets: SIMPLE_CUTOFF and CORE_URBAN_CUTOFF, as here (based on your rules):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data simple_cutoff;
  month='M+0';  _bal_below_cutoff=0;  _bal_not_below_cutoff=10;
  do product_code=20241,20250;              _cutoff=50000;   output;  end;
  do product_code=20109,20110;              _cutoff=5000;    output;  end;
  do product_code=20249,20139,20140;        _cutoff=500000;  output;  end;
  do PRODUCT_CODE=20135,20255,20154,20155;  _cutoff=100000;  output;  end;
  do PRODUCT_CODE =20134,20121;             _cutoff=25000;   output;  end;
run;

data core_urban_cutoff;
  month='M+0';  _bal_below_cutoff=0;  _bal_not_below_cutoff=10;
  do PRODUCT_CODE=20210;
    CORE_URBAN='Urban'; _cutoff=10000; output; 
    CORE_URBAN='Core';  _cutoff=5000;  output; 
  end;

  do PRODUCT_CODE=20204,20201,20202,20203,20205,20206,20207,20211,20212,20213,20214,20215,20216,20217,20218,20219,20220,20221,20222,20223,20224,20225,20226,20227,20228,20229;
    CORE_URBAN='Urban'; _cutoff=10000; output;
    CORE_URBAN='Core';  _cutoff=05000; output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The hash methods&amp;nbsp; &lt;EM&gt;&lt;STRONG&gt;s.find()&lt;/STRONG&gt;&lt;/EM&gt;&amp;nbsp; and &lt;EM&gt;&lt;STRONG&gt;cu.find()&lt;/STRONG&gt;&lt;/EM&gt; return zeroes when the lookup is successful, i.e. matching values of &lt;EM&gt;&lt;STRONG&gt;product_code&lt;/STRONG&gt;&lt;/EM&gt; and &lt;EM&gt;&lt;STRONG&gt;month&lt;/STRONG&gt;&lt;/EM&gt; (and sometimes &lt;EM&gt;&lt;STRONG&gt;core_urban&lt;/STRONG&gt;&lt;/EM&gt;) are found.&amp;nbsp; As part of a "successful" find method, the data values for &lt;EM&gt;&lt;STRONG&gt;_cutoff&lt;/STRONG&gt;&lt;/EM&gt;, &lt;EM&gt;&lt;STRONG&gt;_bal_below_cutoff&lt;/STRONG&gt;&lt;/EM&gt;, and &lt;EM&gt;&lt;STRONG&gt;_bal_not_below_cutoff&lt;/STRONG&gt;&lt;/EM&gt; are retrieved.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have simple cutoff for other months, just modify creation of the simple_cutoff dataset.&amp;nbsp; Similarly for other months that need the core_urban value, just modify creation of the core_urban_cutoff dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Given the absence of sample data, the code above is untested.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, I suggest you print out the cutoff datasets to make sure you've created the intended rules.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 28 Dec 2022 02:51:06 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2022-12-28T02:51:06Z</dc:date>
    <item>
      <title>Looking for any efficient way.</title>
      <link>https://communities.sas.com/t5/SAS-Viya/Looking-for-any-efficient-way/m-p/851111#M1590</link>
      <description>&lt;P&gt;Hey guys, I have to put flags for customers according to their balance for a particular product code. There is categorization on the basis of months as well. As the months increase from M+0 To M+2, upto M+8. Here months M+0 is Current month, M+1 last month and so on.&lt;/P&gt;&lt;P&gt;Is there any other way to do this which does not take so much manual work?&lt;BR /&gt;Any suggestions would be appreciated!&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;DATA PRODWISE_AMB_CHECK;
SET BC_UC_ALL(WHERE=(PRODUCT_CODE NOT IN('20101','20102','20103')));
IF (PRODUCT_CODE IN (20210) AND CORE_URBAN IN ('Urban') AND AMB_OCT_M0&amp;lt;10000 AND MONTH='M+0') OR (PRODUCT_CODE IN (20210) AND CORE_URBAN IN ('Core') AND AMB_OCT_M0&amp;lt;5000 AND MONTH='M+0' ) THEN PROD_BAL=0;
IF (PRODUCT_CODE IN (20210) AND CORE_URBAN IN ('Urban') AND AMB_OCT_M0&amp;gt;=10000 AND MONTH='M+0') OR (PRODUCT_CODE IN (20210) AND CORE_URBAN IN ('Core') AND AMB_OCT_M0&amp;gt;=5000 AND MONTH='M+0' )  THEN PROD_BAL=10;
IF (PRODUCT_CODE IN (20241,20250) AND AMB_OCT_M0&amp;lt;50000 AND MONTH='M+0') THEN PROD_BAL=0;
IF (PRODUCT_CODE IN (20241,20250) AND AMB_OCT_M0&amp;gt;=50000 AND MONTH='M+0') THEN PROD_BAL=10;
IF (PRODUCT_CODE IN (20109,20110) AND AMB_OCT_M0&amp;lt;5000 AND MONTH='M+0') THEN PROD_BAL=0;
IF (PRODUCT_CODE IN (20109,20110) AND AMB_OCT_M0&amp;gt;=5000 AND MONTH='M+0') THEN PROD_BAL=10;
IF (PRODUCT_CODE IN (20249,20139,20140) AND AMB_OCT_M0&amp;lt;500000 AND MONTH='M+0') THEN PROD_BAL=0;
IF (PRODUCT_CODE IN (20249,20139,20140) AND AMB_OCT_M0&amp;gt;=500000 AND MONTH='M+0') THEN PROD_BAL=10;
IF PRODUCT_CODE IN (20135,20255,20154,20155) AND AMB_OCT_M0 &amp;lt;100000 AND MONTH='M+0' THEN PROD_BAL=0;
IF PRODUCT_CODE IN (20135,20255,20154,20155) AND AMB_OCT_M0 &amp;gt;=100000 AND MONTH='M+0' THEN PROD_BAL=10;
IF PRODUCT_CODE IN (20134,20121) AND AMB_OCT_M0 &amp;lt;25000 AND MONTH='M+0'  THEN PROD_BAL=0;
IF PRODUCT_CODE IN (20134,20121) AND AMB_OCT_M0 &amp;gt;=25000  AND MONTH='M+0' THEN PROD_BAL=10;
IF (PRODUCT_CODE IN (20204,20201,20202,20203,20205,20206,20207,20211,20212,20213,20214,20215,20216,20217,20218,20219,20220,20221,20222,20223,20224,20225,20226,20227,20228,20229) AND CORE_URBAN IN ('Urban') AND AMB_OCT_M0&amp;lt;10000 AND MONTH='M+0') 
OR (PRODUCT_CODE IN (20204,20201,20202,20203,20205,20206,20207,20211,20212,20213,20214,20215,20216,20217,20218,20219,20220,20221,20222,20223,20224,20225,20226,20227,20228,20229) AND CORE_URBAN IN ('Core') AND AMB_OCT_M0&amp;lt;5000 AND MONTH='M+0' ) THEN PROD_BAL=0;
IF (PRODUCT_CODE IN (20204,20201,20202,20203,20205,20206,20207,20211,20212,20213,20214,20215,20216,20217,20218,20219,20220,20221,20222,20223,20224,20225,20226,20227,20228,20229) AND CORE_URBAN IN ('Urban') AND AMB_OCT_M0&amp;gt;=10000 AND MONTH='M+0') 
OR (PRODUCT_CODE IN (20204,20201,20202,20203,20205,20206,20207,20211,20212,20213,20214,20215,20216,20217,20218,20219,20220,20221,20222,20223,20224,20225,20226,20227,20228,20229) AND CORE_URBAN IN ('Core') AND AMB_OCT_M0&amp;gt;=5000 AND MONTH='M+0' ) THEN PROD_BAL=10;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 26 Dec 2022 08:15:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Viya/Looking-for-any-efficient-way/m-p/851111#M1590</guid>
      <dc:creator>Discaboota</dc:creator>
      <dc:date>2022-12-26T08:15:06Z</dc:date>
    </item>
    <item>
      <title>Re: Looking for any efficient way.</title>
      <link>https://communities.sas.com/t5/SAS-Viya/Looking-for-any-efficient-way/m-p/851172#M1591</link>
      <description>&lt;P&gt;Your code shows two types of conditions for month='M+0':&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Simple cutoff:&amp;nbsp; &amp;nbsp;For given product codes, there are specific cutoff values for AMB_OCT_M0.&amp;nbsp; In every case when AMB_OCT_M0 is below the cutoff then PROD_BAL=0, otherwise PROD_BAL=10.&lt;BR /&gt;&lt;BR /&gt;&lt;/LI&gt;
&lt;LI&gt;core_urban cutoff.&amp;nbsp; For given product code in combination with core_urban='Urban', or 'Core', there are specific cutoff values.&amp;nbsp; Again, in every case when AMB_OCT_M0 is below the cutoff then PROD_BAL=0, otherwise PROD_BAL=10.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;You can make a dataset for each of these cutoff structures.&amp;nbsp; Then use those datasets as hash objects, for quick lookup of product code, month, (and core_urban) to retrieve the cutoff value, followed by testing AMB_OCT_MO against that cutoff.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's what the code would look like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA PRODWISE_AMB_CHECK (drop=_:);
  SET BC_UC_ALL(WHERE=(PRODUCT_CODE NOT IN('20101','20102','20103')));

  if _n=1 then do;
    if 0 then set simple_cutoff core_urban_cutoff;
    declare hash s (dataset:'simple_cutoff');
      s.definekey('month','product_code');
      s.definedata(all:'Y');
      s.definedone();
    declare hash cu (dataset:'core_urban_cutoff');
      cu.definekey('month','core_urban','product_code');
      cu.definedata(all:'Y');
      cu.definedone();
  end;
  if s.find()=0  then prod_bal=ifn(amb_oct_m0&amp;lt;_cutoff,_bal_below_cutoff,_bal_not_below_cutoff);   else
  if cu.find()=0 then prod_bal=ifn(amb_oct_m0&amp;lt;_cutoff,_bal_below_cutoff,_bal_not_below_cutoff);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This code must be preceded by creating the two datasets: SIMPLE_CUTOFF and CORE_URBAN_CUTOFF, as here (based on your rules):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data simple_cutoff;
  month='M+0';  _bal_below_cutoff=0;  _bal_not_below_cutoff=10;
  do product_code=20241,20250;              _cutoff=50000;   output;  end;
  do product_code=20109,20110;              _cutoff=5000;    output;  end;
  do product_code=20249,20139,20140;        _cutoff=500000;  output;  end;
  do PRODUCT_CODE=20135,20255,20154,20155;  _cutoff=100000;  output;  end;
  do PRODUCT_CODE =20134,20121;             _cutoff=25000;   output;  end;
run;

data core_urban_cutoff;
  month='M+0';  _bal_below_cutoff=0;  _bal_not_below_cutoff=10;
  do PRODUCT_CODE=20210;
    CORE_URBAN='Urban'; _cutoff=10000; output; 
    CORE_URBAN='Core';  _cutoff=5000;  output; 
  end;

  do PRODUCT_CODE=20204,20201,20202,20203,20205,20206,20207,20211,20212,20213,20214,20215,20216,20217,20218,20219,20220,20221,20222,20223,20224,20225,20226,20227,20228,20229;
    CORE_URBAN='Urban'; _cutoff=10000; output;
    CORE_URBAN='Core';  _cutoff=05000; output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The hash methods&amp;nbsp; &lt;EM&gt;&lt;STRONG&gt;s.find()&lt;/STRONG&gt;&lt;/EM&gt;&amp;nbsp; and &lt;EM&gt;&lt;STRONG&gt;cu.find()&lt;/STRONG&gt;&lt;/EM&gt; return zeroes when the lookup is successful, i.e. matching values of &lt;EM&gt;&lt;STRONG&gt;product_code&lt;/STRONG&gt;&lt;/EM&gt; and &lt;EM&gt;&lt;STRONG&gt;month&lt;/STRONG&gt;&lt;/EM&gt; (and sometimes &lt;EM&gt;&lt;STRONG&gt;core_urban&lt;/STRONG&gt;&lt;/EM&gt;) are found.&amp;nbsp; As part of a "successful" find method, the data values for &lt;EM&gt;&lt;STRONG&gt;_cutoff&lt;/STRONG&gt;&lt;/EM&gt;, &lt;EM&gt;&lt;STRONG&gt;_bal_below_cutoff&lt;/STRONG&gt;&lt;/EM&gt;, and &lt;EM&gt;&lt;STRONG&gt;_bal_not_below_cutoff&lt;/STRONG&gt;&lt;/EM&gt; are retrieved.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have simple cutoff for other months, just modify creation of the simple_cutoff dataset.&amp;nbsp; Similarly for other months that need the core_urban value, just modify creation of the core_urban_cutoff dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Given the absence of sample data, the code above is untested.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, I suggest you print out the cutoff datasets to make sure you've created the intended rules.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Dec 2022 02:51:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Viya/Looking-for-any-efficient-way/m-p/851172#M1591</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-12-28T02:51:06Z</dc:date>
    </item>
  </channel>
</rss>

