<?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: Replace name with latest entry in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Replace-name-with-latest-entry/m-p/696467#M79798</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/236597"&gt;@shiv999&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please show what all the rows of data should look like after the code runs with an explanation of the rules being applied.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also if you have tried any code then please share that using the "Insert SAS Code" icon and any log issues using the "Insert Code" icon.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards,&lt;/P&gt;
&lt;P&gt;Amir.&lt;/P&gt;</description>
    <pubDate>Wed, 04 Nov 2020 12:31:00 GMT</pubDate>
    <dc:creator>Amir</dc:creator>
    <dc:date>2020-11-04T12:31:00Z</dc:date>
    <item>
      <title>Replace name with latest entry</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Replace-name-with-latest-entry/m-p/696461#M79796</link>
      <description>Hi guys&lt;BR /&gt;My data is like&lt;BR /&gt;Id. Name $ 10 Doj :date9. dot:date9.;&lt;BR /&gt;11235 Jim 12jul2017 01auj2018&lt;BR /&gt;11235 Jim. 12jul2019 01auj2019&lt;BR /&gt;11235 Jimcarod 12jan2020 01feb2020&lt;BR /&gt;11235 Jimcarod 12jul2020 01auj2020&lt;BR /&gt;&lt;BR /&gt;My code should replace all the row with name Jimcarod . As its is the latest entry and have same id&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 04 Nov 2020 12:21:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Replace-name-with-latest-entry/m-p/696461#M79796</guid>
      <dc:creator>shiv999</dc:creator>
      <dc:date>2020-11-04T12:21:01Z</dc:date>
    </item>
    <item>
      <title>Re: Replace name with latest entry</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Replace-name-with-latest-entry/m-p/696462#M79797</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/236597"&gt;@shiv999&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;BR /&gt;My code should replace all the row with name Jimcarod . As its is the latest entry and have same id&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Please explain this further. Replace what variables with what values in which rows?&lt;/P&gt;</description>
      <pubDate>Wed, 04 Nov 2020 12:23:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Replace-name-with-latest-entry/m-p/696462#M79797</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-11-04T12:23:14Z</dc:date>
    </item>
    <item>
      <title>Re: Replace name with latest entry</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Replace-name-with-latest-entry/m-p/696467#M79798</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/236597"&gt;@shiv999&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please show what all the rows of data should look like after the code runs with an explanation of the rules being applied.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also if you have tried any code then please share that using the "Insert SAS Code" icon and any log issues using the "Insert Code" icon.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards,&lt;/P&gt;
&lt;P&gt;Amir.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Nov 2020 12:31:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Replace-name-with-latest-entry/m-p/696467#M79798</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2020-11-04T12:31:00Z</dc:date>
    </item>
    <item>
      <title>Re: Replace name with latest entry</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Replace-name-with-latest-entry/m-p/696468#M79799</link>
      <description>Replace 1st and 2nd row name column with name in 4th row as it doj date is lastest</description>
      <pubDate>Wed, 04 Nov 2020 12:31:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Replace-name-with-latest-entry/m-p/696468#M79799</guid>
      <dc:creator>shiv999</dc:creator>
      <dc:date>2020-11-04T12:31:10Z</dc:date>
    </item>
    <item>
      <title>Re: Replace name with latest entry</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Replace-name-with-latest-entry/m-p/696476#M79800</link>
      <description>After code changes it should look&lt;BR /&gt;Id Name $ 10 Doj :date9. dot:date9.;&lt;BR /&gt;11235 Jimcarod 12jul2017 01auj2018&lt;BR /&gt;11235 Jimcarod 12jul2019 01auj2019&lt;BR /&gt;11235 Jimcarod 12jan2020 01feb2020&lt;BR /&gt;11235 Jimcarod 12jul2020 01auj2020&lt;BR /&gt;&lt;BR /&gt;I was planning with first. And last dot any suggestions&lt;BR /&gt;</description>
      <pubDate>Wed, 04 Nov 2020 12:42:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Replace-name-with-latest-entry/m-p/696476#M79800</guid>
      <dc:creator>shiv999</dc:creator>
      <dc:date>2020-11-04T12:42:16Z</dc:date>
    </item>
    <item>
      <title>Re: Replace name with latest entry</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Replace-name-with-latest-entry/m-p/696482#M79801</link>
      <description>&lt;P&gt;Can you please create a proper dataset that the community can use or would it be possible for you to provide in the form of neat tabulated format pasted from excel.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Nov 2020 12:55:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Replace-name-with-latest-entry/m-p/696482#M79801</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-11-04T12:55:23Z</dc:date>
    </item>
    <item>
      <title>Re: Replace name with latest entry</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Replace-name-with-latest-entry/m-p/696493#M79802</link>
      <description>Hi thanks so much for your response I have attached the Excel and mentioned before and after changes</description>
      <pubDate>Wed, 04 Nov 2020 13:19:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Replace-name-with-latest-entry/m-p/696493#M79802</guid>
      <dc:creator>shiv999</dc:creator>
      <dc:date>2020-11-04T13:19:50Z</dc:date>
    </item>
    <item>
      <title>Re: Replace name with latest entry</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Replace-name-with-latest-entry/m-p/696495#M79803</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/236597"&gt;@shiv999&lt;/a&gt;&amp;nbsp; Much better. Also, going forward paste the excel here as text rather than attachments-&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input ID 	NAME &amp;amp; $15.	(DateofJoining	DateofTermination) (:date9.);
format DateofJoining	DateofTermination date9.;
cards;
112301	Jim	   1-Jul-17	1-Oct-17
112301	Jim	   1-Nov-17	1-Feb-18
112301	Jim carado	  1-Feb-18	1-Sep-19
112301	Jim carado	  1-Oct-20	1-Nov-20
112302	Ben	   1-Oct-19	2-Nov-20
112302	Ben tamar	 1-Mar-20	3-Nov-20
112303	Lamar	  1-Jun-19	1-May-20
112303	Lamar	  1-Oct-20	1-Nov-20
;

data want;
 do _n_=1 by 1 until(last.id);
  set have;
  by id;
 end;
 _name=name;
 do _n_=1 to _n_;
  set have;
  name=_name;
  output;
 end;
 drop _name;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 04 Nov 2020 13:26:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Replace-name-with-latest-entry/m-p/696495#M79803</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-11-04T13:26:04Z</dc:date>
    </item>
    <item>
      <title>Re: Replace name with latest entry</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Replace-name-with-latest-entry/m-p/696501#M79804</link>
      <description>Thanks you so much , can we do with firstdot And last dot ?</description>
      <pubDate>Wed, 04 Nov 2020 13:37:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Replace-name-with-latest-entry/m-p/696501#M79804</guid>
      <dc:creator>shiv999</dc:creator>
      <dc:date>2020-11-04T13:37:58Z</dc:date>
    </item>
    <item>
      <title>Re: Replace name with latest entry</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Replace-name-with-latest-entry/m-p/696504#M79805</link>
      <description>&lt;P&gt;HI Since you are looking for last name as the value to be used as replacement value, you will need only&lt;STRONG&gt; last dot&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;so-&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input ID 	NAME &amp;amp; $15.	(DateofJoining	DateofTermination) (:date9.);
format DateofJoining	DateofTermination date9.;
cards;
112301	Jim	   1-Jul-17	1-Oct-17
112301	Jim	   1-Nov-17	1-Feb-18
112301	Jim carado	  1-Feb-18	1-Sep-19
112301	Jim carado	  1-Oct-20	1-Nov-20
112302	Ben	   1-Oct-19	2-Nov-20
112302	Ben tamar	 1-Mar-20	3-Nov-20
112303	Lamar	  1-Jun-19	1-May-20
112303	Lamar	  1-Oct-20	1-Nov-20
;

data temp;
 set have;
 by id;
 if last.id;
 _name=name;
 keep id _name;
run;

data want;
 merge have temp;
 by id;
 name=_name;
 drop _name;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Nov 2020 13:43:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Replace-name-with-latest-entry/m-p/696504#M79805</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-11-04T13:43:22Z</dc:date>
    </item>
    <item>
      <title>Re: Replace name with latest entry</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Replace-name-with-latest-entry/m-p/696505#M79806</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/236597"&gt;@shiv999&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for the additional information. As&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;has said text is better than attachments as some of us are prevented from downloading attachments for security reasons, which is very sensible.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the data is not always sorted by doj within id then you could use something like the following.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   input
      id   : 8.
      name : $char10.
      doj  : date9.
      dot  : date9.
   ;

   format
      doj date9.
      dot date9.
   ;

   datalines;
11235 Jim 12jul2017 01aug2018
11235 Jim. 12jul2019 01aug2019
11235 Jimcarod 12jan2020 01feb2020
11235 Jimcarod 12jul2020 01aug2020
;


data want(drop = latest:);
   length latest_name $ 10;

   do until (last.id);
      set have;
      by id;

      latest_doj  = max(latest_doj,doj);
      latest_name = ifc(latest_doj eq doj,name,latest_name);
   end;

   do until (last.id);
      set have;
      by id;

      name = latest_name;
      output;
   end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards,&lt;/P&gt;
&lt;P&gt;Amir.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Nov 2020 13:43:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Replace-name-with-latest-entry/m-p/696505#M79806</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2020-11-04T13:43:26Z</dc:date>
    </item>
  </channel>
</rss>

