<?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: matching two data sets by one year lag using intnx function in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/matching-two-data-sets-by-one-year-lag-using-intnx-function/m-p/531825#M145649</link>
    <description>&lt;P&gt;First, your variables FY and YEARFILED do not appear to be sas date variables.&amp;nbsp; Instead they look like 4-digit numbers (unless they are really sas date values, formatted as YEAR4.).&amp;nbsp; So the INTNX function is useless.&amp;nbsp; If will interpret the value 2004 as&amp;nbsp;27JUN1965 (2004 days after 01jan1960).&amp;nbsp; And subtracting&amp;nbsp;2 years, via the INTNX function, will generate 27JUN1963.&amp;nbsp; So you could replace&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;and fy between intnx('year', yearfiled, -2, "sameday") and yearfiled;
&lt;/PRE&gt;
&lt;P&gt;with&lt;/P&gt;
&lt;PRE&gt;and fy between yearfiled -2  and yearfiled;
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 31 Jan 2019 22:52:45 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2019-01-31T22:52:45Z</dc:date>
    <item>
      <title>matching two data sets by one year lag using intnx function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/matching-two-data-sets-by-one-year-lag-using-intnx-function/m-p/531822#M145648</link>
      <description>&lt;P&gt;Dear All,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have used the following code to merge two data sets,&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table own.want
as select a.*, b.*
from own.sub_9110 as a left join  own.dir_own as b
on a.cusip=b.cusip
and fy between intnx('year', yearfiled, -2, "sameday") and yearfiled;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I want to merge these two datasets by cusip (cusips are already in the same format) and pick up values from own.dir_own data( datasetb) which its fy(year variable in b) is exactly 2 years prior to the yearfield (year variable in a ).&amp;nbsp;&lt;/P&gt;&lt;P&gt;in a, I have thecompany list with cusip and yearfield(like 2004, 2005,...not in month and day format) and in b I have all the director ownership for each company from 1992 till 2018, cusip and fy. So, this means that in b dataset I have more than one director ownership for each company;&lt;/P&gt;&lt;P&gt;Lets say company A in the data set a looks like:&lt;/P&gt;&lt;P&gt;name&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;yearfield&amp;nbsp; &amp;nbsp; &amp;nbsp;cusip&amp;nbsp; &amp;nbsp;.....&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2004&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 12345678&lt;/P&gt;&lt;P&gt;company A in the data set b looks like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;name&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; fy&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; cusip&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; dir_own ....&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1992&amp;nbsp; &amp;nbsp; &amp;nbsp; 12345678&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 45&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1993&amp;nbsp; &amp;nbsp; &amp;nbsp; 12345678&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 12&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2002&amp;nbsp; &amp;nbsp; &amp;nbsp;12345678&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 20&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2004&amp;nbsp; &amp;nbsp; &amp;nbsp;12345678&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 44&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the final merged data set should look like this :&lt;/P&gt;&lt;P&gt;name&amp;nbsp; &amp;nbsp; &amp;nbsp;cusip&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; yearfiled&amp;nbsp; &amp;nbsp; &amp;nbsp;fy&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;dir_own&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;12345678&amp;nbsp; &amp;nbsp; &amp;nbsp;2004&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2002&amp;nbsp; &amp;nbsp; 20&lt;/P&gt;&lt;P&gt;so it picked the director ownership which is 2 years prior to the yearfield;&lt;/P&gt;&lt;P&gt;but the code that i used grabbed all the observation, the final merged data looked like this :&lt;/P&gt;&lt;P&gt;name&amp;nbsp; &amp;nbsp; &amp;nbsp;cusip&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; yearfiled&amp;nbsp; &amp;nbsp; &amp;nbsp; fy&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;dir_own&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;12345678&amp;nbsp; &amp;nbsp; &amp;nbsp;2004&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1992&amp;nbsp; &amp;nbsp; 45&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;12345678&amp;nbsp; &amp;nbsp; &amp;nbsp;2004&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1993&amp;nbsp; &amp;nbsp; 12&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;12345678&amp;nbsp; &amp;nbsp; &amp;nbsp;2004&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2002&amp;nbsp; &amp;nbsp; 20&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;12345678&amp;nbsp; &amp;nbsp; &amp;nbsp;2004&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2004&amp;nbsp; &amp;nbsp; 44&lt;/P&gt;&lt;P&gt;I am not sure how to correct the code, hope you guys can help,&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks in advance.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ziba&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Jan 2019 22:26:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/matching-two-data-sets-by-one-year-lag-using-intnx-function/m-p/531822#M145648</guid>
      <dc:creator>Ziba</dc:creator>
      <dc:date>2019-01-31T22:26:05Z</dc:date>
    </item>
    <item>
      <title>Re: matching two data sets by one year lag using intnx function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/matching-two-data-sets-by-one-year-lag-using-intnx-function/m-p/531825#M145649</link>
      <description>&lt;P&gt;First, your variables FY and YEARFILED do not appear to be sas date variables.&amp;nbsp; Instead they look like 4-digit numbers (unless they are really sas date values, formatted as YEAR4.).&amp;nbsp; So the INTNX function is useless.&amp;nbsp; If will interpret the value 2004 as&amp;nbsp;27JUN1965 (2004 days after 01jan1960).&amp;nbsp; And subtracting&amp;nbsp;2 years, via the INTNX function, will generate 27JUN1963.&amp;nbsp; So you could replace&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;and fy between intnx('year', yearfiled, -2, "sameday") and yearfiled;
&lt;/PRE&gt;
&lt;P&gt;with&lt;/P&gt;
&lt;PRE&gt;and fy between yearfiled -2  and yearfiled;
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Jan 2019 22:52:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/matching-two-data-sets-by-one-year-lag-using-intnx-function/m-p/531825#M145649</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2019-01-31T22:52:45Z</dc:date>
    </item>
    <item>
      <title>Re: matching two data sets by one year lag using intnx function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/matching-two-data-sets-by-one-year-lag-using-intnx-function/m-p/531827#M145650</link>
      <description>&lt;P&gt;No clue what your objective is, &lt;STRONG&gt;but looking only at your data and the want&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data b;
input name   $       fy          cusip                dir_own ;
cards ;
A                 1992      12345678            45
A                 1993      12345678            12
A                 2002     12345678            20
A                2004     12345678            44
;

data a;
input name    $   yearfield     cusip  ;
cards;
A                2004          12345678
;

proc sql;
create table want
as select a.*, fy,dir_own
from a as a left join  b as b
on a.cusip=b.cusip and  fy=yearfield-2;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The above will get you 2002 fy resulting in just 1 record&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The below&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;on a.cusip=b.cusip and fy between yearfield -2  and yearfield;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;will result in 2002 ,2004 with 2 records in result&lt;/P&gt;</description>
      <pubDate>Thu, 31 Jan 2019 23:01:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/matching-two-data-sets-by-one-year-lag-using-intnx-function/m-p/531827#M145650</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-01-31T23:01:52Z</dc:date>
    </item>
    <item>
      <title>Re: matching two data sets by one year lag using intnx function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/matching-two-data-sets-by-one-year-lag-using-intnx-function/m-p/531828#M145651</link>
      <description>&lt;P&gt;You should show what the actual desired output should look like. You show what it shouldn't be but that doesn't say what should.&lt;/P&gt;</description>
      <pubDate>Thu, 31 Jan 2019 22:58:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/matching-two-data-sets-by-one-year-lag-using-intnx-function/m-p/531828#M145651</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-01-31T22:58:39Z</dc:date>
    </item>
    <item>
      <title>Re: matching two data sets by one year lag using intnx function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/matching-two-data-sets-by-one-year-lag-using-intnx-function/m-p/531829#M145652</link>
      <description>&lt;P&gt;what if I formatted the date variables in Year4. format and should I still have to replace?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Jan 2019 23:02:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/matching-two-data-sets-by-one-year-lag-using-intnx-function/m-p/531829#M145652</guid>
      <dc:creator>Ziba</dc:creator>
      <dc:date>2019-01-31T23:02:35Z</dc:date>
    </item>
    <item>
      <title>Re: matching two data sets by one year lag using intnx function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/matching-two-data-sets-by-one-year-lag-using-intnx-function/m-p/531831#M145654</link>
      <description>&lt;P&gt;hey&amp;nbsp;&lt;/P&gt;&lt;P&gt;sorry I didnt say it clearly&amp;nbsp;&lt;/P&gt;&lt;P&gt;the is actual desired output:&lt;/P&gt;&lt;P&gt;name&amp;nbsp; &amp;nbsp; &amp;nbsp;cusip&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; yearfiled&amp;nbsp; &amp;nbsp; &amp;nbsp;fy&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;dir_own&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;12345678&amp;nbsp; &amp;nbsp; &amp;nbsp;2004&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2002&amp;nbsp; &amp;nbsp; 20&lt;/P&gt;</description>
      <pubDate>Thu, 31 Jan 2019 23:05:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/matching-two-data-sets-by-one-year-lag-using-intnx-function/m-p/531831#M145654</guid>
      <dc:creator>Ziba</dc:creator>
      <dc:date>2019-01-31T23:05:34Z</dc:date>
    </item>
    <item>
      <title>Re: matching two data sets by one year lag using intnx function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/matching-two-data-sets-by-one-year-lag-using-intnx-function/m-p/531832#M145655</link>
      <description>&lt;P&gt;hey ,&amp;nbsp;&lt;/P&gt;&lt;P&gt;sorry I didnt say it clearly&amp;nbsp;&lt;/P&gt;&lt;P&gt;the is the actual desired output:&lt;/P&gt;&lt;P&gt;name&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; cusip&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;yearfiled&amp;nbsp; &amp;nbsp; &amp;nbsp;fy&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;dir_own&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;12345678&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2004&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2002&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 20&lt;/P&gt;</description>
      <pubDate>Thu, 31 Jan 2019 23:06:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/matching-two-data-sets-by-one-year-lag-using-intnx-function/m-p/531832#M145655</guid>
      <dc:creator>Ziba</dc:creator>
      <dc:date>2019-01-31T23:06:15Z</dc:date>
    </item>
    <item>
      <title>Re: matching two data sets by one year lag using intnx function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/matching-two-data-sets-by-one-year-lag-using-intnx-function/m-p/531853#M145665</link>
      <description>&lt;P&gt;Which did you do?&lt;/P&gt;</description>
      <pubDate>Fri, 01 Feb 2019 00:55:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/matching-two-data-sets-by-one-year-lag-using-intnx-function/m-p/531853#M145665</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2019-02-01T00:55:11Z</dc:date>
    </item>
    <item>
      <title>Re: matching two data sets by one year lag using intnx function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/matching-two-data-sets-by-one-year-lag-using-intnx-function/m-p/531857#M145667</link>
      <description>&lt;P&gt;I used the following code as I cant format the year variable in data set a. (they all became 1965 after I used year4. format ). this code generated record that are one year prior to yearfiled date.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table own.own_patent_list
as select a.*, b.*
from own.sub_9110 as a left join  own.dir_own as b
on a.cusip=b.cusip
and year=yearfiled-1;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;but I still have one question: I also tried&amp;nbsp; the second code you provided (year between yearfiled-3 and yearfiled-1;) to replace&amp;nbsp;&lt;CODE class=" language-sas"&gt;year=yearfiled-1, and then this time I have maximum of three records for each company. what if I want to pick the first nonzero value within those three rows of records for that company, and delete the rest?&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;I cant use if statement in pro sql, so any ideas ??&amp;nbsp;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;Thanks&lt;/CODE&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Feb 2019 01:19:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/matching-two-data-sets-by-one-year-lag-using-intnx-function/m-p/531857#M145667</guid>
      <dc:creator>Ziba</dc:creator>
      <dc:date>2019-02-01T01:19:01Z</dc:date>
    </item>
  </channel>
</rss>

