<?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 unique identifier from multiple fields, some of which change over time in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Create-unique-identifier-from-multiple-fields-some-of-which/m-p/541312#M7344</link>
    <description>&lt;P&gt;If the loans are sorted by Quarter than the following step seems to solve the problem:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.want;
   set work.loans(drop= LoanTransfer rename=(UniqueId = ExpectedId));

   length 
      UniqueId $ 24
      changedClient changedLoan changedOpenQuarter 8
   ;

   drop changed: lastQuarter;

   retain UniqueId;

   changedClient = lag(Client) ^= Client;
   changedOpenQuarter = lag(OpenQuarter) ^= OpenQuarter;
   changedLoan = lag(Loan) ^= Loan;
   lastQuarter = lag(Quarter);

   if _n_ = 1 or changedClient or changedOpenQuarter or (lastQuarter &amp;gt;= Quarter) then do;
      UniqueId = cats(Loan, '-', Lender);
   end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 08 Mar 2019 07:09:09 GMT</pubDate>
    <dc:creator>andreas_lds</dc:creator>
    <dc:date>2019-03-08T07:09:09Z</dc:date>
    <item>
      <title>Create unique identifier from multiple fields, some of which change over time</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Create-unique-identifier-from-multiple-fields-some-of-which/m-p/540646#M7242</link>
      <description>&lt;P&gt;Good evening,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to create an identifier that will uniquely&amp;nbsp;identify loans in my data over time. The data is quarterly, and a person can be paying multiple loans taken out at different points in time (multiple OpenQuarter values in sample data, below).&amp;nbsp;Currently, a&amp;nbsp;loan is identified uniquely as a combination of person ID, loan ID, and lender ID.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem is that loans are often transferred between lenders; loans can change either lender ID in the process (e.g. observations #5 and #23 in the sample data) or both loan ID and lender ID (e.g. observations #17 and #32 in the sample data). I can figure out when a loan is transferred because it will show up as a "new" loan-lender combination for the person, but the number of loans for that person that were originated in a given quarter will stay the same relative to the previous quarter, the sum of "HiCredit" (maximum loan amount) for loans originated in the same quarter will stay the same, and the total&amp;nbsp;balance for loans originated in the same quarter&amp;nbsp;is very similar ("fuzzy" match).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I am after is the last column, "UniqueID" - a way to track the loan over time. I don't care if this unique ID is the first loan-lender combination, or the last one (after transfer), or a completely new number, as long as I can then properly calculate leads/lags of balance and other&amp;nbsp;fields (many others not&amp;nbsp;shown in data)&amp;nbsp;for a particular loan.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any ideas for how I could accomplish this would be very much appreciated!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sample data below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class="sasSource"&gt;data WORK.IMPORT;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;infile datalines dsd truncover;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;input Obs:BEST12. Client:$18. Loan:$17. Lender:$6. Quarter:MMDDYY10. OpenQuarter:MMDDYY10. Balance:BEST12. HiCredit:BEST12. LoanTransfer:BEST12. UniqueID:$23.;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;format Obs BEST12. Quarter MMDDYY10. OpenQuarter MMDDYY10. Balance BEST12. HiCredit BEST12. LoanTransfer BEST12.;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;datalines;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;1 00C3A26416BBD01F81 029VF12376VU Blue 09/01/2010 09/01/2010 1000 1000 . 029VF12376VU-Blue&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;2 00C3A26416BBD01F81 029VF12376VU Blue 12/01/2010 09/01/2010 2000 2000 . 029VF12376VU-Blue&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;3 00C3A26416BBD01F81 029VF12376VU Blue 03/01/2011 09/01/2010 1900 2000 . 029VF12376VU-Blue&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;4 00C3A26416BBD01F81 029VF12376VU Blue 09/01/2011 09/01/2010 1800 2000 . 029VF12376VU-Blue&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;5 00C3A26416BBD01F81 029VF12376VU Purple 12/01/2011 09/01/2010 1700 2000 1 029VF12376VU-Blue&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;6 00C3A26416BBD01F81 029VF12376VU Purple 03/01/2012 09/01/2010 1600 2000 . 029VF12376VU-Blue&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;7 00C3A26416BBD01F81 029VF12376VU Purple 06/01/2012 09/01/2010 1500 2000 . 029VF12376VU-Blue&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;8 00C3A26416BBD01F81 029VF12376VU Purple 09/01/2012 09/01/2010 1400 2000 . 029VF12376VU-Blue&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;9 00C3A26416BBD01F81 029VF12376VU Purple 12/01/2012 09/01/2010 1300 2000 . 029VF12376VU-Blue&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;10 00C3A26416BBD01F81 HJ-79991272075810 Green 03/01/2010 09/01/2006 3100 3000 . HJ-79991272075810-Green&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;11 00C3A26416BBD01F81 HJ-79991272075810 Green 06/01/2010 09/01/2006 3100 3000 . HJ-79991272075810-Green&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;12 00C3A26416BBD01F81 HJ-79991272075810 Green 09/01/2010 09/01/2006 3100 3000 . HJ-79991272075810-Green&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;13 00C3A26416BBD01F81 HJ-79991272075810 Green 12/01/2010 09/01/2006 3100 3000 . HJ-79991272075810-Green&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;14 00C3A26416BBD01F81 HJ-79991272075810 Green 03/01/2011 09/01/2006 3100 3000 . HJ-79991272075810-Green&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;15 00C3A26416BBD01F81 HJ-79991272075810 Green 06/01/2011 09/01/2006 3100 3000 . HJ-79991272075810-Green&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;16 00C3A26416BBD01F81 HJ-79991272075810 Green 09/01/2011 09/01/2006 3100 3000 . HJ-79991272075810-Green&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;17 00C3A26416BBD01F81 11672365903335X Orange 12/01/2011 09/01/2006 3100 3000 1 HJ-79991272075810-Green&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;18 00C3A26416BBD01F81 11672365903335X Orange 03/01/2012 09/01/2006 3100 3000 . HJ-79991272075810-Green&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;19 00C3A26416BBD01F81 11672365903335X Orange 06/01/2012 09/01/2006 3100 3000 . HJ-79991272075810-Green&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;20 01A48C760A07DEA200 14584QP34577 Purple 03/01/2010 03/01/2006 5000 5000 . 14584QP34577-Purple&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;21 01A48C760A07DEA200 14584QP34577 Purple 06/01/2010 03/01/2006 4900 5000 . 14584QP34577-Purple&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;22 01A48C760A07DEA200 14584QP34577 Purple 09/01/2010 03/01/2006 4800 5000 . 14584QP34577-Purple&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;23 01A48C760A07DEA200 14584QP34577 Green 12/01/2010 03/01/2006 4700 5000 1 14584QP34577-Purple&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;24 01A48C760A07DEA200 14584QP34577 Green 03/01/2012 03/01/2006 4600 5000 . 14584QP34577-Purple&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;25 01A48C760A07DEA200 14584QP34577 Green 06/01/2012 03/01/2006 4500 5000 . 14584QP34577-Purple&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;26 01A48C760A07DEA200 14584QP34577 Green 09/01/2012 03/01/2006 4400 5000 . 14584QP34577-Purple&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;27 01A48C760A07DEA200 14584QP34577 Green 12/01/2012 03/01/2006 4300 5000 . 14584QP34577-Purple&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;28 01A48C760A07DEA200 291FZ Green 12/01/2010 03/01/2006 4100 4000 . 291FZ-Green&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;29 01A48C760A07DEA200 291FZ Green 03/01/2011 03/01/2006 4200 4000 . 291FZ-Green&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;30 01A48C760A07DEA200 291FZ Green 06/01/2011 03/01/2006 4300 4000 . 291FZ-Green&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;31 01A48C760A07DEA200 291FZ Green 09/01/2011 03/01/2006 4400 4000 . 291FZ-Green&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;32 01A48C760A07DEA200 13490999291FZ Orange 12/01/2011 03/01/2006 4500 4000 1 291FZ-Green&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;33 01A48C760A07DEA200 13490999291FZ Orange 03/01/2012 03/01/2006 4600 4000 . 291FZ-Green&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;34 01A48C760A07DEA200 13490999291FZ Orange 06/01/2012 03/01/2006 4700 4000 . 291FZ-Green&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;35 01A48C760A07DEA200 13490999291FZ Orange 09/01/2012 03/01/2006 4800 4000 . 291FZ-Green&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;36 01A48C760A07DEA200 13490999291FZ Orange 12/01/2012 03/01/2006 4900 4000 . 291FZ-Green&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;;;;;&lt;/DIV&gt;</description>
      <pubDate>Wed, 06 Mar 2019 04:41:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Create-unique-identifier-from-multiple-fields-some-of-which/m-p/540646#M7242</guid>
      <dc:creator>dee_arr</dc:creator>
      <dc:date>2019-03-06T04:41:18Z</dc:date>
    </item>
    <item>
      <title>Re: Create unique identifier from multiple fields, some of which change over time</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Create-unique-identifier-from-multiple-fields-some-of-which/m-p/540656#M7245</link>
      <description>&lt;P&gt;Would it be helpful to construct a unique ID from a combination of person ID, loan ID, lender ID and &lt;STRONG&gt;date of loan initiation&lt;/STRONG&gt;?&lt;/P&gt;</description>
      <pubDate>Wed, 06 Mar 2019 06:23:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Create-unique-identifier-from-multiple-fields-some-of-which/m-p/540656#M7245</guid>
      <dc:creator>Norman21</dc:creator>
      <dc:date>2019-03-06T06:23:36Z</dc:date>
    </item>
    <item>
      <title>Re: Create unique identifier from multiple fields, some of which change over time</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Create-unique-identifier-from-multiple-fields-some-of-which/m-p/540710#M7251</link>
      <description>&lt;P&gt;Let's see if i understood, what you have and need.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;LoanTransfer is in your dataset, so you know if that loan has been transferred.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can't use Loan and Lender in your identifier, because when they change it is impossible to create the initially generated identifier for that loan - in obs = 5 you don't have Lender = Blue. Relying on Client + OpenQuarter seems to be impossible, too, because a Client could have more than one loan opened in the same quarter, right?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Mar 2019 09:20:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Create-unique-identifier-from-multiple-fields-some-of-which/m-p/540710#M7251</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2019-03-06T09:20:18Z</dc:date>
    </item>
    <item>
      <title>Re: Create unique identifier from multiple fields, some of which change over time</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Create-unique-identifier-from-multiple-fields-some-of-which/m-p/540748#M7253</link>
      <description>My apologies - LoanTransfer is a field I developed by looking at changes in the following fields:&lt;BR /&gt;&lt;BR /&gt;Sum(count), by OpenQuarter, Quarter, Person ID&lt;BR /&gt;Sum(HiCredit), by OpenQuarter, Quarter, Person ID&lt;BR /&gt;Sum(Balance), by OpenQuarter, Quarter, Person ID&lt;BR /&gt;Running count of unique Loan-Lender combinations within Person&lt;BR /&gt;&lt;BR /&gt;Yes, a person can have more than one loan originated in a quarter, unfortunately. Theoretically, they can have more than one loan originated in a quarter with the same hicredit, but it is extremely rare.&lt;BR /&gt;&lt;BR /&gt;I guess where I get blocked is pulling the Loan/Lender ID of the loan before the transfer once I detect the transfer, so that I can pull it down?</description>
      <pubDate>Wed, 06 Mar 2019 12:07:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Create-unique-identifier-from-multiple-fields-some-of-which/m-p/540748#M7253</guid>
      <dc:creator>dee_arr</dc:creator>
      <dc:date>2019-03-06T12:07:06Z</dc:date>
    </item>
    <item>
      <title>Re: Create unique identifier from multiple fields, some of which change over time</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Create-unique-identifier-from-multiple-fields-some-of-which/m-p/541312#M7344</link>
      <description>&lt;P&gt;If the loans are sorted by Quarter than the following step seems to solve the problem:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.want;
   set work.loans(drop= LoanTransfer rename=(UniqueId = ExpectedId));

   length 
      UniqueId $ 24
      changedClient changedLoan changedOpenQuarter 8
   ;

   drop changed: lastQuarter;

   retain UniqueId;

   changedClient = lag(Client) ^= Client;
   changedOpenQuarter = lag(OpenQuarter) ^= OpenQuarter;
   changedLoan = lag(Loan) ^= Loan;
   lastQuarter = lag(Quarter);

   if _n_ = 1 or changedClient or changedOpenQuarter or (lastQuarter &amp;gt;= Quarter) then do;
      UniqueId = cats(Loan, '-', Lender);
   end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 08 Mar 2019 07:09:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Create-unique-identifier-from-multiple-fields-some-of-which/m-p/541312#M7344</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2019-03-08T07:09:09Z</dc:date>
    </item>
  </channel>
</rss>

