<?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: How to retain the value at each flag occurrence for each unique account? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-retain-the-value-at-each-flag-occurrence-for-each-unique/m-p/725494#M225364</link>
    <description>&lt;P&gt;One way might be:&lt;/P&gt;
&lt;PRE&gt;data want; 
   set example;
   by accno;
   retain new_amount;
   if first.accno then new_amount=.;
   if flag and amount then new_amount=amount;
   if missing(flag) then new_amount=.;
run;&lt;/PRE&gt;
&lt;P&gt;This works for the provided example.&lt;/P&gt;
&lt;P&gt;The " if flag and amount then new_amount=amount;" works if flag and amount are not 0 as SAS treats non-zero non-missing numeric values as "true". If zero is a possible valid value for either then use&lt;/P&gt;
&lt;PRE&gt;if not missing(flag) and not missing(amount) then new_amount=amount;&lt;/PRE&gt;
&lt;P&gt;You did not show if the Flag value might ever be missing after it was set within an Accno group. I am guessing that you likely would want to reset the new_amount to missing if that every occurs.&lt;/P&gt;</description>
    <pubDate>Thu, 11 Mar 2021 16:22:39 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2021-03-11T16:22:39Z</dc:date>
    <item>
      <title>How to retain the value at each flag occurrence for each unique account?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-retain-the-value-at-each-flag-occurrence-for-each-unique/m-p/725481#M225355</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Would require assistance to achieve the following new amount value to be inputted based on a flag and the specified amount tied to it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please find screenshot for reference. For each account number, I would like to RETAIN the first amount at each occurrence of flag and affect subsequent records below. Once there's a new amount, it will take in the new amount and bring it down to the subsequent rows below. This behavior applies to the same account number until it reaches a new account number.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sas_newbie94_0-1615479045716.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/55818i7B4CAC2095607623/image-size/medium?v=v2&amp;amp;px=400" role="button" title="sas_newbie94_0-1615479045716.png" alt="sas_newbie94_0-1615479045716.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;data example;&lt;BR /&gt;input accno flag amount ;&lt;BR /&gt;datalines;&lt;BR /&gt;100 . .&lt;BR /&gt;100 . .&lt;BR /&gt;100 . .&lt;BR /&gt;100 . .&lt;BR /&gt;100 1 1000&lt;BR /&gt;100 1 .&lt;BR /&gt;100 1 .&lt;BR /&gt;100 1 .&lt;BR /&gt;100 1 3000&lt;BR /&gt;100 1 .&lt;/P&gt;
&lt;P&gt;200 . .&lt;BR /&gt;200 . .&lt;BR /&gt;200 . .&lt;BR /&gt;200 . .&lt;BR /&gt;200 . .&lt;BR /&gt;200 1 500&lt;BR /&gt;200 1 .&lt;BR /&gt;200 1 .&lt;BR /&gt;200 1 700&lt;BR /&gt;200 1 .&lt;BR /&gt;;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Mar 2021 16:11:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-retain-the-value-at-each-flag-occurrence-for-each-unique/m-p/725481#M225355</guid>
      <dc:creator>sas_newbie94</dc:creator>
      <dc:date>2021-03-11T16:11:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to retain the value at each flag occurrence for each unique account?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-retain-the-value-at-each-flag-occurrence-for-each-unique/m-p/725494#M225364</link>
      <description>&lt;P&gt;One way might be:&lt;/P&gt;
&lt;PRE&gt;data want; 
   set example;
   by accno;
   retain new_amount;
   if first.accno then new_amount=.;
   if flag and amount then new_amount=amount;
   if missing(flag) then new_amount=.;
run;&lt;/PRE&gt;
&lt;P&gt;This works for the provided example.&lt;/P&gt;
&lt;P&gt;The " if flag and amount then new_amount=amount;" works if flag and amount are not 0 as SAS treats non-zero non-missing numeric values as "true". If zero is a possible valid value for either then use&lt;/P&gt;
&lt;PRE&gt;if not missing(flag) and not missing(amount) then new_amount=amount;&lt;/PRE&gt;
&lt;P&gt;You did not show if the Flag value might ever be missing after it was set within an Accno group. I am guessing that you likely would want to reset the new_amount to missing if that every occurs.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Mar 2021 16:22:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-retain-the-value-at-each-flag-occurrence-for-each-unique/m-p/725494#M225364</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-03-11T16:22:39Z</dc:date>
    </item>
  </channel>
</rss>

