<?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: Create new date variable based on specific condition in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Create-new-date-variable-based-on-specific-condition/m-p/927022#M41586</link>
    <description>&lt;P&gt;Hello &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/464169"&gt;@tan-wongv&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;If you want the outcome as you have shown, then you would need to modify &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt; 's code as follow&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input DMRN $ last_visit :date. UI recorded_time :date.;
  format last_visit recorded_time date9.;
cards;
31 26AUG2021 0 06APR2018
31 26AUG2021 0 16JAN2020
31 26AUG2021 1 4MAY2021
31 26AUG2021 1 26MAY2022
33 24MAY2022 0 02MAR2020
33 24MAY2022 0 24MAY2022
35 01DEC2014 0 25MAR2013
35 01DEC2014 1 05JAN2015
;

data want ;
  set have;
  if ui=1 then new_date = recorded_time;
  else if ui=0 and DMRN=31 then new_date="04MAY2021"d;
  else new_date = last_visit;
  format new_date date9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The result would be as you wished&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Sajid01_0-1714832835085.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/96179iDDADA4E6D1E867C4/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Sajid01_0-1714832835085.png" alt="Sajid01_0-1714832835085.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 04 May 2024 14:27:25 GMT</pubDate>
    <dc:creator>Sajid01</dc:creator>
    <dc:date>2024-05-04T14:27:25Z</dc:date>
    <item>
      <title>Create new date variable based on specific condition</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Create-new-date-variable-based-on-specific-condition/m-p/926222#M41569</link>
      <description>&lt;P&gt;I have a data set contains DMRN, last visit date, the presence of UI, and recorded date of UI.&lt;/P&gt;
&lt;TABLE width="50"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;DMRN&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;last_visit&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;UI&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;recorded_time&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;31&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;26AUG2021&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;0&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;06APR2018&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;31&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;26AUG2021&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;0&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;16JAN2020&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;&lt;STRONG&gt;31&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;&lt;STRONG&gt;26AUG2021&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;&lt;STRONG&gt;4MAY2021&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;33&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;24MAY2022&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;0&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;02MAR2020&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;33&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;24MAY2022&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;0&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;24MAY2022&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;35&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;01DEC2014&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;0&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;25MAR2013&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to create new_date for each DMRN based on these conditions: &lt;BR /&gt;if UI = 1 then new_date = recorded_time&lt;BR /&gt;else if UI = 0 then new_date = last_visit&lt;BR /&gt;The outcome would be like as follow:&amp;nbsp;&lt;/P&gt;
&lt;TABLE style="width: 50px;" border="1" width="411px"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="58.7969px" height="30px"&gt;DMRN&lt;/TD&gt;
&lt;TD width="100.703px" height="30px"&gt;last_visit&lt;/TD&gt;
&lt;TD width="40px" height="30px"&gt;UI&lt;/TD&gt;
&lt;TD width="113.344px" height="30px"&gt;recorded_time&lt;/TD&gt;
&lt;TD width="100.703px" height="30px"&gt;new_date&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="58.7969px" height="30px"&gt;31&lt;/TD&gt;
&lt;TD width="100.703px" height="30px"&gt;26AUG2021&lt;/TD&gt;
&lt;TD width="40px" height="30px"&gt;0&lt;/TD&gt;
&lt;TD width="113.344px" height="30px"&gt;06APR2018&lt;/TD&gt;
&lt;TD width="100.703px" height="30px"&gt;&lt;STRONG&gt;4MAY2021&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="58.7969px" height="30px"&gt;31&lt;/TD&gt;
&lt;TD width="100.703px" height="30px"&gt;26AUG2021&lt;/TD&gt;
&lt;TD width="40px" height="30px"&gt;0&lt;/TD&gt;
&lt;TD width="113.344px" height="30px"&gt;16JAN2020&lt;/TD&gt;
&lt;TD width="100.703px" height="30px"&gt;&lt;STRONG&gt;4MAY2021&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="58.7969px" height="30px"&gt;31&lt;/TD&gt;
&lt;TD width="100.703px" height="30px"&gt;26AUG2021&lt;/TD&gt;
&lt;TD width="40px" height="30px"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="113.344px" height="30px"&gt;&lt;STRONG&gt;4MAY2021&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="100.703px" height="30px"&gt;&lt;STRONG&gt;4MAY2021&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="58.7969px" height="30px"&gt;33&lt;/TD&gt;
&lt;TD width="100.703px" height="30px"&gt;24MAY2022&lt;/TD&gt;
&lt;TD width="40px" height="30px"&gt;0&lt;/TD&gt;
&lt;TD width="113.344px" height="30px"&gt;
&lt;P&gt;02MAR2020&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="100.703px" height="30px"&gt;24MAY2022&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="58.7969px" height="30px"&gt;33&lt;/TD&gt;
&lt;TD width="100.703px" height="30px"&gt;24MAY2022&lt;/TD&gt;
&lt;TD width="40px" height="30px"&gt;0&lt;/TD&gt;
&lt;TD width="113.344px" height="30px"&gt;24MAY2022&lt;/TD&gt;
&lt;TD width="100.703px" height="30px"&gt;24MAY2022&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="58.7969px" height="30px"&gt;35&lt;/TD&gt;
&lt;TD width="100.703px" height="30px"&gt;01DEC2014&lt;/TD&gt;
&lt;TD width="40px" height="30px"&gt;0&lt;/TD&gt;
&lt;TD width="113.344px" height="30px"&gt;25MAR2013&lt;/TD&gt;
&lt;TD width="100.703px" height="30px"&gt;01DEC2014&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could you please help me with the code? Thank you very much&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 28 Apr 2024 18:16:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Create-new-date-variable-based-on-specific-condition/m-p/926222#M41569</guid>
      <dc:creator>tan-wongv</dc:creator>
      <dc:date>2024-04-28T18:16:01Z</dc:date>
    </item>
    <item>
      <title>Re: Create new date variable based on specific condition</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Create-new-date-variable-based-on-specific-condition/m-p/926226#M41571</link>
      <description>&lt;P&gt;You seem to have already written the code.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Did you try running it?&amp;nbsp; What happened?&lt;/P&gt;
&lt;LI-SPOILER&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  if UI = 1 then new_date = recorded_time;
  else if UI = 0 then new_date = last_visit;
  format new_date date9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/LI-SPOILER&gt;</description>
      <pubDate>Sun, 28 Apr 2024 19:26:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Create-new-date-variable-based-on-specific-condition/m-p/926226#M41571</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-04-28T19:26:38Z</dc:date>
    </item>
    <item>
      <title>Re: Create new date variable based on specific condition</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Create-new-date-variable-based-on-specific-condition/m-p/926234#M41575</link>
      <description>&lt;P&gt;This code works for those who have UI = 0, new_date is equal to last_visit&lt;/P&gt;
&lt;P&gt;However, it did not work for those who have UI = 1, such as DMRN 31. I would like new_date for DMRN31 to be as 4MAY2021 4MAY2021 4MAY2021&amp;nbsp;&lt;/P&gt;
&lt;TABLE style="width: 50px;" border="1" width="50px"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="58.7969px" height="30px"&gt;DMRN&lt;/TD&gt;
&lt;TD width="100.703px" height="30px"&gt;last_visit&lt;/TD&gt;
&lt;TD width="40px" height="30px"&gt;UI&lt;/TD&gt;
&lt;TD width="40px" height="30px"&gt;recorded_time&lt;/TD&gt;
&lt;TD width="40px" height="30px"&gt;new_date&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="58.7969px" height="30px"&gt;31&lt;/TD&gt;
&lt;TD width="100.703px" height="30px"&gt;&lt;SPAN&gt;26AUG2021&lt;/SPAN&gt;&lt;/TD&gt;
&lt;TD width="40px" height="30px"&gt;0&lt;/TD&gt;
&lt;TD width="40px" height="30px"&gt;&lt;SPAN&gt;06APR2018&lt;/SPAN&gt;&lt;/TD&gt;
&lt;TD width="40px" height="30px"&gt;&lt;SPAN&gt;26AUG2021&lt;/SPAN&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="58.7969px" height="30px"&gt;31&lt;/TD&gt;
&lt;TD width="100.703px" height="30px"&gt;&lt;SPAN&gt;26AUG2021&lt;/SPAN&gt;&lt;/TD&gt;
&lt;TD width="40px" height="30px"&gt;0&lt;/TD&gt;
&lt;TD width="40px" height="30px"&gt;&lt;SPAN&gt;16JAN2020&lt;/SPAN&gt;&lt;/TD&gt;
&lt;TD width="40px" height="30px"&gt;&lt;SPAN&gt;26AUG2021&lt;/SPAN&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="58.7969px" height="30px"&gt;31&lt;/TD&gt;
&lt;TD width="100.703px" height="30px"&gt;&lt;SPAN&gt;26AUG2021&lt;/SPAN&gt;&lt;/TD&gt;
&lt;TD width="40px" height="30px"&gt;1&lt;/TD&gt;
&lt;TD width="40px" height="30px"&gt;&lt;STRONG&gt;4MAY2021&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="40px" height="30px"&gt;&lt;STRONG&gt;4MAY2021&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="58.7969px" height="30px"&gt;33&lt;/TD&gt;
&lt;TD width="100.703px" height="30px"&gt;24MAY2022&lt;/TD&gt;
&lt;TD width="40px" height="30px"&gt;0&lt;/TD&gt;
&lt;TD width="40px" height="30px"&gt;&lt;SPAN&gt;02MAR2020&lt;/SPAN&gt;&lt;/TD&gt;
&lt;TD width="40px" height="30px"&gt;24MAY2022&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="58.7969px" height="30px"&gt;33&lt;/TD&gt;
&lt;TD width="100.703px" height="30px"&gt;24MAY2022&lt;/TD&gt;
&lt;TD width="40px" height="30px"&gt;0&lt;/TD&gt;
&lt;TD width="40px" height="30px"&gt;&lt;SPAN&gt;24MAY2022&lt;/SPAN&gt;&lt;/TD&gt;
&lt;TD width="40px" height="30px"&gt;24MAY2022&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="58.7969px" height="30px"&gt;35&lt;/TD&gt;
&lt;TD width="100.703px" height="30px"&gt;&lt;SPAN&gt;01DEC2014&lt;/SPAN&gt;&lt;/TD&gt;
&lt;TD width="40px" height="30px"&gt;0&lt;/TD&gt;
&lt;TD width="40px" height="30px"&gt;&lt;SPAN&gt;25MAR2013&lt;/SPAN&gt;&lt;/TD&gt;
&lt;TD width="40px" height="30px"&gt;&lt;SPAN&gt;01DEC2014&lt;/SPAN&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Mon, 29 Apr 2024 00:04:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Create-new-date-variable-based-on-specific-condition/m-p/926234#M41575</guid>
      <dc:creator>tan-wongv</dc:creator>
      <dc:date>2024-04-29T00:04:08Z</dc:date>
    </item>
    <item>
      <title>Re: Create new date variable based on specific condition</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Create-new-date-variable-based-on-specific-condition/m-p/926239#M41576</link>
      <description>&lt;P&gt;Works fine.&lt;/P&gt;
&lt;P&gt;Are you sure you want the extra IF in there?&amp;nbsp; What value do you want for NEW_VAR when UI is neither 1 nor zero?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input DMRN $ last_visit :date. UI recorded_time :date.;
  format last_visit recorded_time date9.;
cards;
31 26AUG2021 0 06APR2018
31 26AUG2021 0 16JAN2020
31 26AUG2021 1 4MAY2021
31 26AUG2021 1 26MAY2022
33 24MAY2022 0 02MAR2020
33 24MAY2022 0 24MAY2022
35 01DEC2014 0 25MAR2013
35 01DEC2014 1 05JAN2015
;

data want ;
  set have;
  if ui=1 then new_var = recorded_time;
  else new_var = last_visit;
  format new_var date9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;                   last_          recorded_
Obs    DMRN        visit    UI      time         new_var

 1      31     26AUG2021     0    06APR2018    26AUG2021
 2      31     26AUG2021     0    16JAN2020    26AUG2021
 3      31     26AUG2021     1    04MAY2021    04MAY2021
 4      31     26AUG2021     1    26MAY2022    26MAY2022
 5      33     24MAY2022     0    02MAR2020    24MAY2022
 6      33     24MAY2022     0    24MAY2022    24MAY2022
 7      35     01DEC2014     0    25MAR2013    01DEC2014
 8      35     01DEC2014     1    05JAN2015    05JAN2015&lt;/PRE&gt;
&lt;P&gt;Again &lt;STRONG&gt;check that the values of UI are actually integers&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Apr 2024 01:02:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Create-new-date-variable-based-on-specific-condition/m-p/926239#M41576</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-04-29T01:02:03Z</dc:date>
    </item>
    <item>
      <title>Re: Create new date variable based on specific condition</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Create-new-date-variable-based-on-specific-condition/m-p/926244#M41577</link>
      <description>&lt;P&gt;If&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;'s code doesn't return the desired result then run below and investigate any row that gets written to table Investigate.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data investigate ;
  set have;
  if ui not in (0,1) then output;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or here another way to check what values you've actually got in UI.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=have;
  table ui;
run;
proc contents data=have(keep=ui);
run;quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 29 Apr 2024 01:51:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Create-new-date-variable-based-on-specific-condition/m-p/926244#M41577</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-04-29T01:51:30Z</dc:date>
    </item>
    <item>
      <title>Re: Create new date variable based on specific condition</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Create-new-date-variable-based-on-specific-condition/m-p/926257#M41578</link>
      <description>&lt;P&gt;Is it guaranteed that each dmrn has 0 or 1 obs with ui = 1, or could there be more obs with ui = 1?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-SPOILER&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ui;
   set have(
         keep= DMRN recorded_time ui 
         rename=(recorded_time = new_date)
         where=(ui = 1)
      );

   drop ui;
run;


data want;
   set have;

   length new_date 8;
   format new_date date9.;

   if _n_ = 1 then do;
      declare hash h(dataset: 'ui');
      h.defineKey('dmrn');
      h.defineData('new_date');
      h.defineDone();
   end;

   if h.find() ^= 0 then do;
      new_date = recorded_time;
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/LI-SPOILER&gt;</description>
      <pubDate>Mon, 29 Apr 2024 06:22:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Create-new-date-variable-based-on-specific-condition/m-p/926257#M41578</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2024-04-29T06:22:52Z</dc:date>
    </item>
    <item>
      <title>Re: Create new date variable based on specific condition</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Create-new-date-variable-based-on-specific-condition/m-p/927022#M41586</link>
      <description>&lt;P&gt;Hello &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/464169"&gt;@tan-wongv&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;If you want the outcome as you have shown, then you would need to modify &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt; 's code as follow&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input DMRN $ last_visit :date. UI recorded_time :date.;
  format last_visit recorded_time date9.;
cards;
31 26AUG2021 0 06APR2018
31 26AUG2021 0 16JAN2020
31 26AUG2021 1 4MAY2021
31 26AUG2021 1 26MAY2022
33 24MAY2022 0 02MAR2020
33 24MAY2022 0 24MAY2022
35 01DEC2014 0 25MAR2013
35 01DEC2014 1 05JAN2015
;

data want ;
  set have;
  if ui=1 then new_date = recorded_time;
  else if ui=0 and DMRN=31 then new_date="04MAY2021"d;
  else new_date = last_visit;
  format new_date date9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The result would be as you wished&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Sajid01_0-1714832835085.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/96179iDDADA4E6D1E867C4/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Sajid01_0-1714832835085.png" alt="Sajid01_0-1714832835085.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 04 May 2024 14:27:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Create-new-date-variable-based-on-specific-condition/m-p/927022#M41586</guid>
      <dc:creator>Sajid01</dc:creator>
      <dc:date>2024-05-04T14:27:25Z</dc:date>
    </item>
  </channel>
</rss>

