<?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 JOIN 1 to many with dates Question in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/JOIN-1-to-many-with-dates-Question/m-p/604107#M175094</link>
    <description>&lt;P&gt;So I have an interesting problem that I am hoping I can find an answer for.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a work file that I created with: (Work.Test_1)&lt;/P&gt;
&lt;P&gt;Team Number&lt;/P&gt;
&lt;P&gt;Unique Player ID&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Date Played (this can be many dates)&amp;nbsp; (DATETIME22.3 format) &amp;lt;-- I know I will need to select a MAX and convert to a YYYYMM format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have another table (Work.new_table) that I want to join to obtain Category.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The issue is that this table is sorted with a date format of 201911.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So what I am looking to do is something like below&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Proc Sql;
create table work.test_2 as
select

Team_Number,
Unique_Player_ID,
Category

from work.new_table

where Team_Number in (select Team_Number from work.test_1) and 
Unique_Player_ID in (select Unique_Player_ID from work.test_1) and
Date in select (Max Date_Played)

order by 1;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thank you&lt;/P&gt;</description>
    <pubDate>Thu, 14 Nov 2019 14:21:33 GMT</pubDate>
    <dc:creator>IgawaKei29</dc:creator>
    <dc:date>2019-11-14T14:21:33Z</dc:date>
    <item>
      <title>JOIN 1 to many with dates Question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/JOIN-1-to-many-with-dates-Question/m-p/604107#M175094</link>
      <description>&lt;P&gt;So I have an interesting problem that I am hoping I can find an answer for.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a work file that I created with: (Work.Test_1)&lt;/P&gt;
&lt;P&gt;Team Number&lt;/P&gt;
&lt;P&gt;Unique Player ID&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Date Played (this can be many dates)&amp;nbsp; (DATETIME22.3 format) &amp;lt;-- I know I will need to select a MAX and convert to a YYYYMM format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have another table (Work.new_table) that I want to join to obtain Category.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The issue is that this table is sorted with a date format of 201911.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So what I am looking to do is something like below&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Proc Sql;
create table work.test_2 as
select

Team_Number,
Unique_Player_ID,
Category

from work.new_table

where Team_Number in (select Team_Number from work.test_1) and 
Unique_Player_ID in (select Unique_Player_ID from work.test_1) and
Date in select (Max Date_Played)

order by 1;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Thu, 14 Nov 2019 14:21:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/JOIN-1-to-many-with-dates-Question/m-p/604107#M175094</guid>
      <dc:creator>IgawaKei29</dc:creator>
      <dc:date>2019-11-14T14:21:33Z</dc:date>
    </item>
    <item>
      <title>Re: JOIN 1 to many with dates Question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/JOIN-1-to-many-with-dates-Question/m-p/604262#M175166</link>
      <description>&lt;P&gt;It's quite unclear what you're wanting without a sample dataset. If my solution isn't what you're looking for, I strongly suggest posting a 'have' and 'want' data sample so that others may help answer your question -- create the 'have' as a data step as opposed to posting pictures or anything like that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's an example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Using SASHELP.TIMEDATA to create an analogous dataset to the one I think you have:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
	value team
	1-2 = 1
	3-5 = 2
	;
	value cat
	1-2 = "Baseball"
	3-5 = "Basketball"
	;
run;

proc sort data=sashelp.timedata(where=(volume le 5)) 
	out=raw(rename=(volume=player_id datetime=date_played) ); 
	by volume datetime;
run;

proc sort data=raw nodupkey out=players(keep=player_id);
by player_id;
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;2. 'have' and 'player_info' should be in the form of what you're calling test_1 and new_table&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have(drop=count);
	set raw;
	count+1;
	by player_id;
	if first.player_id then count=1;
	if count le 5 then output;
run;

data player_info;
set players;
team_number=input(put(player_id,team.),8.);
category=put(player_id,cat.);
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;3. Merge the results so that player info is joined to the set with the dates_played.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
merge have(in=a) player_info(in=b);
by player_id;
if a;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;-unison&lt;/P&gt;</description>
      <pubDate>Thu, 14 Nov 2019 20:00:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/JOIN-1-to-many-with-dates-Question/m-p/604262#M175166</guid>
      <dc:creator>unison</dc:creator>
      <dc:date>2019-11-14T20:00:00Z</dc:date>
    </item>
  </channel>
</rss>

