<?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: join two tables with dummy in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/join-two-tables-with-dummy/m-p/347799#M63653</link>
    <description>&lt;P&gt;Sorry it is a mistake I put&amp;nbsp;&lt;SPAN&gt;Year(B.rankdate)=A.year&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I am sure that my program does not seem good.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Can you please formulate your solution more clearly&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 06 Apr 2017 15:51:46 GMT</pubDate>
    <dc:creator>sasphd</dc:creator>
    <dc:date>2017-04-06T15:51:46Z</dc:date>
    <item>
      <title>join two tables with dummy</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/join-two-tables-with-dummy/m-p/347788#M63649</link>
      <description>&lt;P&gt;I have table A and B to join to obtain table C&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data A;&lt;BR /&gt;input year$ yr2007$ yr2008$ yr2009$;&lt;BR /&gt;cards;&lt;BR /&gt;2007 1 0 0&lt;BR /&gt;2008 0 1 0&lt;BR /&gt;2009 0 0 1&lt;BR /&gt;run;&lt;BR /&gt;data B;&lt;BR /&gt;input rank_no$ rankdate$ ;&lt;BR /&gt;cards;&lt;BR /&gt;1 20071231 &lt;BR /&gt;1 20081231 &lt;BR /&gt;1 20091231 &lt;BR /&gt;2 20071231 &lt;BR /&gt;2 20081231 &lt;BR /&gt;2 20091231 &lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;data C;&lt;BR /&gt;input rank_no$ rankdate$ yr2007$ yr2008$ yr2009$ ;&lt;BR /&gt;cards;&lt;BR /&gt;1 20071231 1 0 0&lt;BR /&gt;1 20081231 0 1 0&lt;BR /&gt;1 20091231 0 0 1&lt;BR /&gt;2 20071231 1 0 0&lt;BR /&gt;2 20081231 0 1 0&lt;BR /&gt;2 20091231 0 0 1&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Apr 2017 15:37:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/join-two-tables-with-dummy/m-p/347788#M63649</guid>
      <dc:creator>sasphd</dc:creator>
      <dc:date>2017-04-06T15:37:36Z</dc:date>
    </item>
    <item>
      <title>Re: join two tables with dummy</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/join-two-tables-with-dummy/m-p/347790#M63650</link>
      <description>&lt;P&gt;Create a year variable in data set B and merge on that value.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Apr 2017 15:38:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/join-two-tables-with-dummy/m-p/347790#M63650</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-04-06T15:38:59Z</dc:date>
    </item>
    <item>
      <title>Re: join two tables with dummy</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/join-two-tables-with-dummy/m-p/347794#M63651</link>
      <description>&lt;P&gt;I do this and it did not work can you help me please!!!!!!!!!!!!!!!!!!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt; create table JOINT_fixed as&lt;BR /&gt; select Distinct A.*, B.*&lt;BR /&gt; from B&lt;BR /&gt; Left join A&amp;nbsp;&lt;BR /&gt; on Year(B.rankdate)=Year(A.year) &lt;BR /&gt; quit;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Apr 2017 15:45:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/join-two-tables-with-dummy/m-p/347794#M63651</guid>
      <dc:creator>sasphd</dc:creator>
      <dc:date>2017-04-06T15:45:56Z</dc:date>
    </item>
    <item>
      <title>Re: join two tables with dummy</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/join-two-tables-with-dummy/m-p/347797#M63652</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4327"&gt;@sasphd&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;I do this and it did not work can you help me please!!!!!!!!!!!!!!!!!!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt; create table JOINT_fixed as&lt;BR /&gt; select Distinct A.*, B.*&lt;BR /&gt; from B&lt;BR /&gt; Left join A&amp;nbsp;&lt;BR /&gt; on Year(B.rankdate)=Year(A.year) &lt;BR /&gt; quit;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;What happens when you do year(year)??????How can you take the year of a year?????Why a left join?????&lt;/P&gt;
&lt;P&gt;Chwck your logic.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Apr 2017 15:49:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/join-two-tables-with-dummy/m-p/347797#M63652</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-04-06T15:49:11Z</dc:date>
    </item>
    <item>
      <title>Re: join two tables with dummy</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/join-two-tables-with-dummy/m-p/347799#M63653</link>
      <description>&lt;P&gt;Sorry it is a mistake I put&amp;nbsp;&lt;SPAN&gt;Year(B.rankdate)=A.year&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I am sure that my program does not seem good.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Can you please formulate your solution more clearly&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Apr 2017 15:51:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/join-two-tables-with-dummy/m-p/347799#M63653</guid>
      <dc:creator>sasphd</dc:creator>
      <dc:date>2017-04-06T15:51:46Z</dc:date>
    </item>
    <item>
      <title>Re: join two tables with dummy</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/join-two-tables-with-dummy/m-p/347812#M63654</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4327"&gt;@sasphd&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Sorry it is a mistake I put&amp;nbsp;&lt;SPAN&gt;Year(B.rankdate)=A.year&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I am sure that my program does not seem good.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Can you please formulate your solution more clearly&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Does it work?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A SQL solution is the correct answer. Your sample data is misleading because you read everything in as character although its numeric.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4327"&gt;@sasphd&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Can you please formulate your solution more clearly&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;A join/merge is one of the very basics of working with data, week0, it's worth spending some time to understand it and learn it.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There's an entire 'chapter' on the topic in the documentation/user guide.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://support.sas.com/documentation/cdl/en/lrcon/69852/HTML/default/viewer.htm#p15jvywi5avt3cn1bee8r6c33ux1.htm" target="_blank"&gt;https://support.sas.com/documentation/cdl/en/lrcon/69852/HTML/default/viewer.htm#p15jvywi5avt3cn1bee8r6c33ux1.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Apr 2017 16:12:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/join-two-tables-with-dummy/m-p/347812#M63654</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-04-06T16:12:42Z</dc:date>
    </item>
    <item>
      <title>Re: join two tables with dummy</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/join-two-tables-with-dummy/m-p/347827#M63655</link>
      <description>&lt;P&gt;All my problem is that I never suceed to put data correctly in your forum. You have tried to help me to do it but I did not suceed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Apr 2017 16:36:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/join-two-tables-with-dummy/m-p/347827#M63655</guid>
      <dc:creator>sasphd</dc:creator>
      <dc:date>2017-04-06T16:36:15Z</dc:date>
    </item>
    <item>
      <title>Re: join two tables with dummy</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/join-two-tables-with-dummy/m-p/347832#M63656</link>
      <description>&lt;P&gt;Please see:&lt;/P&gt;
&lt;PRE&gt;data A;
input year yr2007 yr2008 yr2009;
cards;
2007 1 0 0
2008 0 1 0
2009 0 0 1
run;
data B;
informat rankdate yymmdd.;
format rankdate yymmdd10.;
input rank_no rankdate ;
cards;
1 20071231 
1 20081231 
1 20091231 
2 20071231 
2 20081231 
2 20091231 
run;

proc sql;
   create table JOINT_fixed as
   select Distinct A.*, B.*
   from B
   Left join A 
   on Year(B.rankdate)= A.year ;
quit;&lt;/PRE&gt;
&lt;P&gt;To use the year function as in Year(b.rankdate) the variable b.rankdate must be a SAS datevalue to make sense. I modified the example code to use numeric values as that makes more sense then reading everything as character values (which is what those $ do) and used a specific informat to read the RANKDATE variable as a date value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also since the variable A.year is already a year value then the function Year(a.year) is not needed, just compare the actual value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your existing data for the variables is actually all character you may want to go back a step or two&amp;nbsp; in your process and change things to get numeric values.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Apr 2017 16:48:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/join-two-tables-with-dummy/m-p/347832#M63656</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-04-06T16:48:26Z</dc:date>
    </item>
    <item>
      <title>Re: join two tables with dummy</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/join-two-tables-with-dummy/m-p/347836#M63658</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4327"&gt;@sasphd&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;All my problem is that I never suceed to put data correctly in your forum. You have tried to help me to do it but I did not suceed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This is not 'my forum'. &amp;nbsp;I have no affiliation with SAS.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Apr 2017 16:59:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/join-two-tables-with-dummy/m-p/347836#M63658</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-04-06T16:59:55Z</dc:date>
    </item>
    <item>
      <title>Re: join two tables with dummy</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/join-two-tables-with-dummy/m-p/347850#M63662</link>
      <description>I know, thanks for your help Reeza</description>
      <pubDate>Thu, 06 Apr 2017 17:34:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/join-two-tables-with-dummy/m-p/347850#M63662</guid>
      <dc:creator>sasphd</dc:creator>
      <dc:date>2017-04-06T17:34:26Z</dc:date>
    </item>
  </channel>
</rss>

