<?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 How to update values based on date in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-update-values-based-on-date/m-p/984280#M46429</link>
    <description>&lt;P&gt;Multiple transaction defined by date and assigned values YES and NO.&amp;nbsp; Looking forward to write the code that keeps YES until NO starts based on descending condition. If YES is between NO values, should be overwritten as NO. Below few samples, I am dealing with large dataset.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Before change&lt;/STRONG&gt;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;01/10/2025&lt;/TD&gt;&lt;TD&gt;YES&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;01/09/2025&lt;/TD&gt;&lt;TD&gt;YES&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;01/08/2025&lt;/TD&gt;&lt;TD&gt;YES&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;01/07/2025&lt;/TD&gt;&lt;TD&gt;YES&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;01/06/2025&lt;/TD&gt;&lt;TD&gt;YES&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;01/05/2025&lt;/TD&gt;&lt;TD&gt;NO&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;01/04/2025&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;YES&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;01/03/2025&lt;/TD&gt;&lt;TD&gt;NO&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;01/02/2025&lt;/TD&gt;&lt;TD&gt;NO&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;AFTER CHANGE&lt;/STRONG&gt;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;01/10/2025&lt;/TD&gt;&lt;TD&gt;YES&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;01/09/2025&lt;/TD&gt;&lt;TD&gt;YES&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;01/08/2025&lt;/TD&gt;&lt;TD&gt;YES&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;01/07/2025&lt;/TD&gt;&lt;TD&gt;YES&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;01/06/2025&lt;/TD&gt;&lt;TD&gt;YES&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;01/05/2025&lt;/TD&gt;&lt;TD&gt;NO&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;01/04/2025&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;NO&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;01/03/2025&lt;/TD&gt;&lt;TD&gt;NO&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;01/02/2025&lt;/TD&gt;&lt;TD&gt;NO&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
    <pubDate>Mon, 02 Mar 2026 17:28:19 GMT</pubDate>
    <dc:creator>vaidas</dc:creator>
    <dc:date>2026-03-02T17:28:19Z</dc:date>
    <item>
      <title>How to update values based on date</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-update-values-based-on-date/m-p/984280#M46429</link>
      <description>&lt;P&gt;Multiple transaction defined by date and assigned values YES and NO.&amp;nbsp; Looking forward to write the code that keeps YES until NO starts based on descending condition. If YES is between NO values, should be overwritten as NO. Below few samples, I am dealing with large dataset.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Before change&lt;/STRONG&gt;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;01/10/2025&lt;/TD&gt;&lt;TD&gt;YES&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;01/09/2025&lt;/TD&gt;&lt;TD&gt;YES&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;01/08/2025&lt;/TD&gt;&lt;TD&gt;YES&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;01/07/2025&lt;/TD&gt;&lt;TD&gt;YES&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;01/06/2025&lt;/TD&gt;&lt;TD&gt;YES&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;01/05/2025&lt;/TD&gt;&lt;TD&gt;NO&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;01/04/2025&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;YES&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;01/03/2025&lt;/TD&gt;&lt;TD&gt;NO&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;01/02/2025&lt;/TD&gt;&lt;TD&gt;NO&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;AFTER CHANGE&lt;/STRONG&gt;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;01/10/2025&lt;/TD&gt;&lt;TD&gt;YES&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;01/09/2025&lt;/TD&gt;&lt;TD&gt;YES&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;01/08/2025&lt;/TD&gt;&lt;TD&gt;YES&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;01/07/2025&lt;/TD&gt;&lt;TD&gt;YES&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;01/06/2025&lt;/TD&gt;&lt;TD&gt;YES&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;01/05/2025&lt;/TD&gt;&lt;TD&gt;NO&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;01/04/2025&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;NO&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;01/03/2025&lt;/TD&gt;&lt;TD&gt;NO&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;01/02/2025&lt;/TD&gt;&lt;TD&gt;NO&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Mon, 02 Mar 2026 17:28:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-update-values-based-on-date/m-p/984280#M46429</guid>
      <dc:creator>vaidas</dc:creator>
      <dc:date>2026-03-02T17:28:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to update values based on date</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-update-values-based-on-date/m-p/984281#M46430</link>
      <description>&lt;P&gt;You don't say this, and I hate to assume this is what you mean, but I am going to ask. Does this data set have multiple ID values (perhaps multiple transactions?) Should the conversion of YES to NO be applied to each ID value?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please make this clear in your description, and also add in any other information that we might need to write the code.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Mar 2026 17:36:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-update-values-based-on-date/m-p/984281#M46430</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2026-03-02T17:36:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to update values based on date</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-update-values-based-on-date/m-p/984282#M46431</link>
      <description>&lt;P&gt;Valid point. Thanks for asking. Above example was for just for one ID, however there are multiple ID's with multiple transaction dates. YES and NO are for each transaction.&amp;nbsp; YES should be overwritten&amp;nbsp; as example above.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Mar 2026 17:46:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-update-values-based-on-date/m-p/984282#M46431</guid>
      <dc:creator>vaidas</dc:creator>
      <dc:date>2026-03-02T17:46:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to update values based on date</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-update-values-based-on-date/m-p/984283#M46432</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    by transaction_id;
    retain flag;
    if first.transaction_id then flag=0;
    if yn='NO' then flag=1;
    if flag=1 then yn='NO';
    drop flag;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The above code is untested. If you want tested code, you need to provide data as working SAS data step code (&lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;examples and instructions&lt;/A&gt;), and not as copy/paste from Excel or other program. Since you have more than 1 transaction in your real data, you need to provide us with data that has more than 1 transaction ID so we can test if the code works properly.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Mar 2026 18:12:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-update-values-based-on-date/m-p/984283#M46432</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2026-03-02T18:12:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to update values based on date</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-update-values-based-on-date/m-p/984303#M46434</link>
      <description>&lt;P&gt;The problem seems to be that you want to treat the NO blocks differently based on whether or not they are at the END of of the list of not.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also you did not provide instructions for what to do when the first observation has a NO value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since it is easier to remember the past than predict the future it would probably be easier if the data was sorted by increasing date instead of the decreasing date order you provided.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So assuming you have an ID variable and your date variable is an actual numeric variable with date values that just happens to have a format attached that makes them print in that style (I cannot tell from your printout if you want the dates to print in MDY or DMY order. )&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could do something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  do until (last.id);
     set have;
     by id date ;
     if flag='YES' then any_yes=1;
     if any_yes then flag='YES';
     output;
  end;
  drop any_yes;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that including DATE in the BY statement will allow SAS to detect it the observations are not actually sorted by ascending date values with each ID value.&lt;/P&gt;</description>
      <pubDate>Tue, 03 Mar 2026 01:57:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-update-values-based-on-date/m-p/984303#M46434</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2026-03-03T01:57:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to update values based on date</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-update-values-based-on-date/m-p/984308#M46436</link>
      <description>&lt;P&gt;There are too many scenarios you need to consider about.&lt;/P&gt;
&lt;PRE&gt;data have;
infile cards expandtabs;
input id date : mmddyy10. flag $;
format date mmddyy10.;
cards;
1 01/10/2025	YES
1 01/09/2025	YES
1 01/08/2025	YES
1 01/07/2025	YES
1 01/06/2025	YES
1 01/05/2025	NO
1 01/04/2025	YES
1 01/03/2025	NO
1 01/02/2025	NO
;

proc sql;
create table want as
select *,case when flag='YES'
 and 
(select count(*) from have  where id=a.id and flag='NO' and date&amp;lt;a.date)
and
(select count(*) from have  where id=a.id and flag='NO' and date&amp;gt;a.date)
then 'NO' else flag end as new_flag
 from have as a
  order by id,date desc;
quit;
&lt;/PRE&gt;
&lt;DIV id="tinyMceEditorKsharp_0" class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="屏幕截图 2026-03-03 155044.png" style="width: 448px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/113431i823B6EF87B699F78/image-size/large?v=v2&amp;amp;px=999" role="button" title="屏幕截图 2026-03-03 155044.png" alt="屏幕截图 2026-03-03 155044.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Mar 2026 07:51:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-update-values-based-on-date/m-p/984308#M46436</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2026-03-03T07:51:12Z</dc:date>
    </item>
  </channel>
</rss>

