<?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: Variable changes based on previous value in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Variable-changes-based-on-previous-value/m-p/430624#M27797</link>
    <description>&lt;P&gt;In general, you're going to get vague answers unless you posts sample data. Sample data does not need to be real data but it should mimic your structure and complexity.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, the vague answer.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Use BY processing to identify new users in groups.&lt;/P&gt;
&lt;P&gt;2. Use LAG() to get the previous value.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3. Use RETAIN to keep a value across rows&amp;nbsp;&lt;/P&gt;
&lt;P&gt;4. IFN() can likely do what you need.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;score = ifn( &amp;lt; condition&amp;gt;, /*condition based on previous value and other logic*/
max(score+5, 15) , /*increment to max of 15*/
score - 1 /*decrement score*/
)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also:&lt;/P&gt;
&lt;P&gt;1. Are you guaranteed to have continuous data? If not, how should that be dealt with?&lt;/P&gt;
&lt;P&gt;2. Are you caclulating from scratch each time or 'adding' in new data with the appropriate calculation&lt;/P&gt;
&lt;P&gt;3. Do you need to retain previous scores?&lt;/P&gt;
&lt;P&gt;4. Is the data subject to revision, if so, #2 is really important&lt;/P&gt;
&lt;P&gt;5. Does efficiency matter, this can be relatively easy&amp;nbsp;to program but if you have tens of millions you may want a more efficient approach.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 24 Jan 2018 19:44:21 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2018-01-24T19:44:21Z</dc:date>
    <item>
      <title>Variable changes based on previous value</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Variable-changes-based-on-previous-value/m-p/430594#M27794</link>
      <description>&lt;P&gt;Hello All -&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'll try to explain this one the best I can but I fear it may come across wonky over text.&amp;nbsp; I have a program I have created that generates a "risk score" which is the total number of triggers hit and some weighting.&amp;nbsp; A trigger is a specific pharmacy behavior in this instance.&amp;nbsp; The program I have now just assigns a value of 1 to each trigger and aggregates them to get the final score.&amp;nbsp; What I need to figure out how to code is say we have the use of a product A as a trigger with a maximum value of 15.&amp;nbsp; However, for a good reason, we do not want the first appearance of this action to add&amp;nbsp;15 points to the overall score.&amp;nbsp; Say the first appearance we want 5, then if this product is paid for again in the following month (this will run on a monthly basis) the score should be 10, and if it is bought a third month the score tops out at 15 and will remain 15 no matter how many more consecutive months the product is paid for.&amp;nbsp; Now, the same thing goes for a month where the product is not purchased.&amp;nbsp; Say the product was purchased two months in a row, if the following month comes and it is not purchased, we want the total number of points this product adds to the score to be 5.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So essentially, I need to incrementally raise and lower the point value this variable adds to my score based off prior months' runs of the program.&amp;nbsp; Previous months runs can be stored on a monthly basis if needed, but we could also just recalculate previous runs' scores each run.&amp;nbsp;&amp;nbsp;Any help on how to do this would be greatly appreciated.&amp;nbsp;&amp;nbsp;&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;Andrew&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jan 2018 18:59:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Variable-changes-based-on-previous-value/m-p/430594#M27794</guid>
      <dc:creator>sasspan</dc:creator>
      <dc:date>2018-01-24T18:59:08Z</dc:date>
    </item>
    <item>
      <title>Re: Variable changes based on previous value</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Variable-changes-based-on-previous-value/m-p/430603#M27795</link>
      <description>&lt;P&gt;You will need to describe your data further.&amp;nbsp; Too much of the programming depends on that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you have a separate data set for each month?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is in a single observation?&amp;nbsp; Just one trigger, or just one person with many triggers?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Did I understand the rule correctly, that absence of a trigger for a month lowers the score going forward?&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jan 2018 19:14:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Variable-changes-based-on-previous-value/m-p/430603#M27795</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-01-24T19:14:54Z</dc:date>
    </item>
    <item>
      <title>Re: Variable changes based on previous value</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Variable-changes-based-on-previous-value/m-p/430605#M27796</link>
      <description>&lt;P&gt;Do you have a separate data set for each month? - I was thinking of just having one final dataset and saving over it each month&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is in a single observation?&amp;nbsp; Just one trigger, or just one person with many triggers? the final data set is at the claim level (one person) with many triggers (now 0/1 but instead of 1, want the point values going forward) However, to get to the final table, there's transactional level data - 1 prescription = 1 observation&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Did I understand the rule correctly, that absence of a trigger for a month lowers the score going forward? Yes, to 0 being the minimum&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jan 2018 19:20:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Variable-changes-based-on-previous-value/m-p/430605#M27796</guid>
      <dc:creator>sasspan</dc:creator>
      <dc:date>2018-01-24T19:20:06Z</dc:date>
    </item>
    <item>
      <title>Re: Variable changes based on previous value</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Variable-changes-based-on-previous-value/m-p/430624#M27797</link>
      <description>&lt;P&gt;In general, you're going to get vague answers unless you posts sample data. Sample data does not need to be real data but it should mimic your structure and complexity.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, the vague answer.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Use BY processing to identify new users in groups.&lt;/P&gt;
&lt;P&gt;2. Use LAG() to get the previous value.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3. Use RETAIN to keep a value across rows&amp;nbsp;&lt;/P&gt;
&lt;P&gt;4. IFN() can likely do what you need.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;score = ifn( &amp;lt; condition&amp;gt;, /*condition based on previous value and other logic*/
max(score+5, 15) , /*increment to max of 15*/
score - 1 /*decrement score*/
)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also:&lt;/P&gt;
&lt;P&gt;1. Are you guaranteed to have continuous data? If not, how should that be dealt with?&lt;/P&gt;
&lt;P&gt;2. Are you caclulating from scratch each time or 'adding' in new data with the appropriate calculation&lt;/P&gt;
&lt;P&gt;3. Do you need to retain previous scores?&lt;/P&gt;
&lt;P&gt;4. Is the data subject to revision, if so, #2 is really important&lt;/P&gt;
&lt;P&gt;5. Does efficiency matter, this can be relatively easy&amp;nbsp;to program but if you have tens of millions you may want a more efficient approach.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jan 2018 19:44:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Variable-changes-based-on-previous-value/m-p/430624#M27797</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-01-24T19:44:21Z</dc:date>
    </item>
    <item>
      <title>Re: Variable changes based on previous value</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Variable-changes-based-on-previous-value/m-p/430652#M27800</link>
      <description>&lt;P&gt;I'm going to run the code once, and create a history table.&amp;nbsp; Then I'll join to this history table each month.&amp;nbsp; Add 5, unless adding 5 exceeds 15 then 15 for when the activity occurs.&amp;nbsp; Subtract 5 unless subtracting is less than 0 then 0 for when it does not occur.&amp;nbsp; I was over complicating this in my head.&amp;nbsp; Sorry, I'll except Reeza's response as he's basically there.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jan 2018 20:11:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Variable-changes-based-on-previous-value/m-p/430652#M27800</guid>
      <dc:creator>sasspan</dc:creator>
      <dc:date>2018-01-24T20:11:39Z</dc:date>
    </item>
    <item>
      <title>Re: Variable changes based on previous value</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Variable-changes-based-on-previous-value/m-p/430655#M27801</link>
      <description>She.</description>
      <pubDate>Wed, 24 Jan 2018 20:13:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Variable-changes-based-on-previous-value/m-p/430655#M27801</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-01-24T20:13:09Z</dc:date>
    </item>
  </channel>
</rss>

