<?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 change a variable's value based on certain criteria across multiple observations in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-change-a-variable-s-value-based-on-certain-criteria/m-p/915311#M360650</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to do what is described in the title. For example,&amp;nbsp; I am trying to determine how to make a continuous date and then delete the 2 duplicated to create 1 observation from the three. I have 3 observations, all sharing the same main variable (ID#). The other two variables, start date and stop date, should be continues if the time between those two dates is &amp;lt;2. So, like (fake dates) 02/28-03/11, 03/12-03/30. How can I code my programming to make it appear as 02/28-03/30 then delete the two duplicates.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 09 Feb 2024 17:26:37 GMT</pubDate>
    <dc:creator>tomhead19</dc:creator>
    <dc:date>2024-02-09T17:26:37Z</dc:date>
    <item>
      <title>How to change a variable's value based on certain criteria across multiple observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-change-a-variable-s-value-based-on-certain-criteria/m-p/915311#M360650</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to do what is described in the title. For example,&amp;nbsp; I am trying to determine how to make a continuous date and then delete the 2 duplicated to create 1 observation from the three. I have 3 observations, all sharing the same main variable (ID#). The other two variables, start date and stop date, should be continues if the time between those two dates is &amp;lt;2. So, like (fake dates) 02/28-03/11, 03/12-03/30. How can I code my programming to make it appear as 02/28-03/30 then delete the two duplicates.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Feb 2024 17:26:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-change-a-variable-s-value-based-on-certain-criteria/m-p/915311#M360650</guid>
      <dc:creator>tomhead19</dc:creator>
      <dc:date>2024-02-09T17:26:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to change a variable's value based on certain criteria across multiple observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-change-a-variable-s-value-based-on-certain-criteria/m-p/915333#M360657</link>
      <description>&lt;P&gt;What you are asking is how to collapse a time interval.&amp;nbsp;&amp;nbsp;You want to collapse ranges where the GAP between them is smaller 3 days.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is a common question on SAS communities.&amp;nbsp; &amp;nbsp;For example see this recent thread.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/How-to-collapse-time-intervals-contingent-upon-some-arguments/td-p/895949" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/How-to-collapse-time-intervals-contingent-upon-some-arguments/td-p/895949&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;They did not allow a gap.&amp;nbsp; So just adjust the logic that is comparing the follow-up start dates to the previous end dates to allow your gap size.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Feb 2024 18:57:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-change-a-variable-s-value-based-on-certain-criteria/m-p/915333#M360657</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-02-09T18:57:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to change a variable's value based on certain criteria across multiple observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-change-a-variable-s-value-based-on-certain-criteria/m-p/915337#M360659</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
set
  have (
    firstobs=2
    keep=id start_dt
    rename=(id=_id start_dt=_start)
  )
  have (
    obs=1
    keep=id start_dt
    rename=(id=-id start_dt=_start)
  )
;
retain _begin;
if _n_ = 1 then _begin = start_dt;
if id ne _id or _start gt stop_dt + 1
then do;
  start_dt = _begin;
  output;
  _begin = _start;
end;
drop _:;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Untested, posted from my tablet.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Feb 2024 19:15:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-change-a-variable-s-value-based-on-certain-criteria/m-p/915337#M360659</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-02-09T19:15:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to change a variable's value based on certain criteria across multiple observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-change-a-variable-s-value-based-on-certain-criteria/m-p/915438#M360705</link>
      <description>&lt;P&gt;So you have to (1) look back to see if the current obs is a new id, or follows a gap that is too large, and (2) look forward to see if the current obs is the last for a given id, or precedes a gap that is too large.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Untested, in the absence of sample data in the form of a working DATA step:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let max_gap=2;  /* Maximum allowable "hole" size */

data want (drop=_:);
  merge have
        have (firstobs=2 keep=id start_date rename=(id=_nxt_id start_date=_nxt_start));

  retain _initial_start;
  if id^=lag(id) or start-&amp;amp;max_gap &amp;gt; lag(stop_date) then _initial_start=start_date;

  if (id^=_nxt_id)  or  (_nxt_start &amp;gt; stop_date+&amp;amp;max_gap) ; /*Subsetting IF*/
  start_date=_initial_start;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This code assumes that the data are grouped by ID, and are sorted chronologically within ID.&lt;/P&gt;</description>
      <pubDate>Sun, 11 Feb 2024 16:23:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-change-a-variable-s-value-based-on-certain-criteria/m-p/915438#M360705</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2024-02-11T16:23:45Z</dc:date>
    </item>
  </channel>
</rss>

