<?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: job code Tenure in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/job-code-Tenure/m-p/673983#M202866</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp; Thanks for your Reply.&lt;/P&gt;&lt;P&gt;The current logic calculates the date correctly for the transaction of 16th july (i.e the cre_dt is 15th July)&lt;/P&gt;&lt;P&gt;but for the transaction of 13th july the cre_dt should be 13th jan-19 because the job code LA started on 13 jan-19&lt;/P&gt;&lt;P&gt;current logic calculates the cre_dt for the transaction of 13 july as 13 jun-2020&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again for your help..&lt;/P&gt;</description>
    <pubDate>Sun, 02 Aug 2020 11:48:20 GMT</pubDate>
    <dc:creator>soham_sas</dc:creator>
    <dc:date>2020-08-02T11:48:20Z</dc:date>
    <item>
      <title>job code Tenure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/job-code-Tenure/m-p/673941#M202840</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&amp;nbsp;i have a employee level transactions data which shows type of transaction and the date of the transaction that the employee did&lt;/P&gt;&lt;P&gt;i have one more data which has the employee job information( the table is shown below ) , i have to calculate the job code tenure of the employee&amp;nbsp;&lt;/P&gt;&lt;P&gt;The logic to calculate the job code tenure is like this : lets say the employee did transactions on 13th and 16th july-2020&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;then against the 16th july i have to mark CA as the job code and the tenure will be (16july-15-jul) ,and this is because on 16th july the date less then 16th july is 15th july , and the job code was CA.&lt;/LI&gt;&lt;LI&gt;for 13th july i have to mark LA as the job code and the tenure will be (13th july- 13 Jan) , and this is because on 13th july the date less then 13th july is 13 jun , and the job code was LA which started from 13-jan-19&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Please note that job code CA is repeated after the LA , we shouldn't consider these while calculating the tenure for 15th july.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i have also attached the below table in Excel format.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;EMP_ID&lt;/TD&gt;&lt;TD&gt;Job_cd&lt;/TD&gt;&lt;TD&gt;cre_dt&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;CA&lt;/TD&gt;&lt;TD&gt;15-Jul-20&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;LA&lt;/TD&gt;&lt;TD&gt;13-Jun-20&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;LA&lt;/TD&gt;&lt;TD&gt;12-Jun-20&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;LA&lt;/TD&gt;&lt;TD&gt;02-May-20&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;LA&lt;/TD&gt;&lt;TD&gt;13-Jan-19&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;CA&lt;/TD&gt;&lt;TD&gt;12-Dec-19&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;CA&lt;/TD&gt;&lt;TD&gt;11-Oct-19&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;DA&lt;/TD&gt;&lt;TD&gt;01-Jan-18&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;DA&lt;/TD&gt;&lt;TD&gt;01-Jun-18&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;DA&lt;/TD&gt;&lt;TD&gt;15-Nov-18&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Sat, 01 Aug 2020 17:38:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/job-code-Tenure/m-p/673941#M202840</guid>
      <dc:creator>soham_sas</dc:creator>
      <dc:date>2020-08-01T17:38:55Z</dc:date>
    </item>
    <item>
      <title>Re: job code Tenure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/job-code-Tenure/m-p/673952#M202847</link>
      <description>&lt;P&gt;Let's see if I understand:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One table (call it T) has one record per employee/transaction.&amp;nbsp; It has employee id (ID), transaction date (TDATE) and various other transaction related variables.&amp;nbsp;&amp;nbsp; The other table (call it J, for which you provide a sample) is a table of some sort of employee job code&amp;nbsp; change.&amp;nbsp; It has one record per change for each employee.&amp;nbsp; It has variables ID,&amp;nbsp; jobcode-change-date (CRE_DT in your example), and job code (JOB_CD).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For some reason your table J appears to be sorted by ID&amp;nbsp; and &lt;EM&gt;&lt;STRONG&gt;descending (!)&lt;/STRONG&gt;&lt;/EM&gt; CRE_DT.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let's assume, however that table T is sorted by ID and &lt;EM&gt;&lt;STRONG&gt;ascending&lt;/STRONG&gt;&lt;/EM&gt; TDATE.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now, if J is not very big, I would first sort it by ID and ascending CRE_DT, first, as here:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=J  out=Jprime;
  by id cre_dt;
run;

data want;
  set Jprime (keep=id cre_dt rename=(cre_dt=tdate) in=inJ) T (in=inT);
  by id tdate ;&lt;BR /&gt;  /* if first.id then call missing (of _all_); */
  if inJ then set Jprime ;
  if inT;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The data WANT step works this way:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;The first SET statement interleave data from Jprime and T, sorted by ID and tdate (temporarily renaming CRE_DT to TDATE to satisfy the "by id tdate" statement.&amp;nbsp; Importantly the &lt;EM&gt;&lt;STRONG&gt;variable JOB_CD from Jprime is NOT retrieved here&lt;/STRONG&gt;&lt;/EM&gt;.&lt;BR /&gt;&lt;BR /&gt;&lt;/LI&gt;
&lt;LI&gt;Note that Jprime precedes T in the set statement, because you will want to carry forward the CR_JOB value (from dataset Jprime) to the subsequent transaction (from T).&amp;nbsp;&amp;nbsp; This could be tricky if the dates of the two datasets were identical, but putting Jprime before T in the set statement guarantees that the Jprime record is processed prior to the T record.&lt;BR /&gt;&lt;BR /&gt;&lt;/LI&gt;
&lt;LI&gt;If the record in hand comes dataset Jprime, do a conditional set (IF inJ then set Jprime), to reread the J record, this time with CRE_DT not renamed and, crucially, this time also with the JOB_CD variable.&amp;nbsp; Those JOB_CD and CRE_DT values will persist across subsequent T observations until another J record is encountered, and triggers this conditional set statement again.&lt;BR /&gt;&lt;BR /&gt;&lt;/LI&gt;
&lt;LI&gt;Finally, do a subsetting if, keeping only instances matching a transaction record.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;This program assumes that there will always be a J record preceding the earliest T record for each ID.&amp;nbsp; If not, then de-comment the call missing statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now, what if your J dataset is too big to sort, and you'd rather process it in its current pathologically sorted order?&amp;nbsp; Then you could first read in all the J records, and save the job codes in a cre_dt-indexed array.&amp;nbsp; Then when the T records are read start with cre_dt=tdate and go backwards until a non-blank job_cd is retrieved from the array:&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;BR /&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let mindate=01jan2015;&lt;BR /&gt;%let maxdate=31dec2019;&lt;BR /&gt;&lt;BR /&gt;data want;
  set J (in=inJ)  T (in=inT);
  by id;
  array jcodes {%sysevalf("&amp;amp;mindate"d):%sysevalf("&amp;amp;maxdate"d)} $2 _temporary_ ;
  if first.id then call missing(of jcodes{*});
  if inJ then jcodes{cre_dt}=job_cd;

  if inT;
  do cre_dt=tdate to "&amp;amp;mindate"d by -1 until(job_cd^=' ');
     job_cd=jcodes{cre_dt};
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;OL&gt;
&lt;LI&gt;Set the macrovars mindate and maxdate to value you know will span the entire range of dates in your datasets.&lt;/LI&gt;
&lt;LI&gt;The array JCODES has be set to be a array of $2 variables, since I assume that is the length of JOB_CD.&amp;nbsp; It is a _temporary_ array, meaning it won't appear on the output dataset, and its values are retained accross subsequent observations.&amp;nbsp; The array index lower bound is the underlying value for 01jan2015 and the upper bound is 31dec2019.&amp;nbsp;&lt;/LI&gt;
&lt;LI&gt;the BY statement is now only "by id", not "by id tdate", since you want to read ALL of the J records prior to reading the first T record.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 01 Aug 2020 22:09:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/job-code-Tenure/m-p/673952#M202847</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-08-01T22:09:18Z</dc:date>
    </item>
    <item>
      <title>Re: job code Tenure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/job-code-Tenure/m-p/673983#M202866</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp; Thanks for your Reply.&lt;/P&gt;&lt;P&gt;The current logic calculates the date correctly for the transaction of 16th july (i.e the cre_dt is 15th July)&lt;/P&gt;&lt;P&gt;but for the transaction of 13th july the cre_dt should be 13th jan-19 because the job code LA started on 13 jan-19&lt;/P&gt;&lt;P&gt;current logic calculates the cre_dt for the transaction of 13 july as 13 jun-2020&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again for your help..&lt;/P&gt;</description>
      <pubDate>Sun, 02 Aug 2020 11:48:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/job-code-Tenure/m-p/673983#M202866</guid>
      <dc:creator>soham_sas</dc:creator>
      <dc:date>2020-08-02T11:48:20Z</dc:date>
    </item>
    <item>
      <title>Re: job code Tenure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/job-code-Tenure/m-p/674012#M202881</link>
      <description>&lt;P&gt;I'd be happy to address this.&amp;nbsp; Please provide SAS data steps with relevant parts of the two tables, so that I can actually test the code.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 02 Aug 2020 20:18:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/job-code-Tenure/m-p/674012#M202881</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-08-02T20:18:49Z</dc:date>
    </item>
  </channel>
</rss>

