<?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 tables in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Join-tables/m-p/197100#M49240</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The same code works OK with the new supposition: if all values of PWPUMAS are the same then MAX(PWPUMAS) is this value for each IN_PUMA_ID&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can also use the following code assuming both files are sorted by IN_PUMA_ID and PWPUMAS has the same value for each IN_PUMA_ID:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Data new;&lt;/P&gt;&lt;P&gt;&amp;nbsp; merge Agearank (in=in_rank) Agea (keep=IN_PUMA_ID PWPUMAS);&lt;/P&gt;&lt;P&gt;&amp;nbsp; by IN_PUMA_ID;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if in_rank;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CTorres&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 23 Apr 2015 19:48:45 GMT</pubDate>
    <dc:creator>CTorres</dc:creator>
    <dc:date>2015-04-23T19:48:45Z</dc:date>
    <item>
      <title>Join tables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Join-tables/m-p/197095#M49235</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have the following dataset called "Agearank" containing 2,042 observations.&lt;/P&gt;&lt;P&gt;&lt;IMG alt="Capture.PNG" class="jive-image" src="https://communities.sas.com/legacyfs/online/10057_Capture.PNG" /&gt;&lt;/P&gt;&lt;P&gt;I also have another dataset called "Agea" containing 28,031 observations. &lt;/P&gt;&lt;P&gt;&lt;IMG alt="f.PNG" class="jive-image" src="https://communities.sas.com/legacyfs/online/10059_f.PNG" /&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;I would like to join "Agea" into "Agearank" by IN_PUMA_ID. My goal is to attach the variable PWPUMAS (i.e., Super-PUMA of work) in the &lt;SPAN style="font-size: 13.3333330154419px;"&gt;"Agea" dataset to the "Agearank" dataset. In the newly created dataset (e.g., new), I would only like to have &lt;SPAN style="font-size: 13.3333330154419px;"&gt;2,042 observations&lt;/SPAN&gt; based on the &lt;SPAN style="font-size: 13.3333330154419px;"&gt;"Agearank" dataset. How should I write the SAS code? Thank you.&lt;/SPAN&gt;&lt;/SPAN&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Apr 2015 05:22:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Join-tables/m-p/197095#M49235</guid>
      <dc:creator>MichaelLin</dc:creator>
      <dc:date>2015-04-16T05:22:09Z</dc:date>
    </item>
    <item>
      <title>Re: Join tables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Join-tables/m-p/197096#M49236</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;There are many values of the variable PWPUMAS for each IN_PUMA_ID. You need to chose what of them to attach. Maybe MAX(PWPUMAS) ?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Apr 2015 14:20:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Join-tables/m-p/197096#M49236</guid>
      <dc:creator>CTorres</dc:creator>
      <dc:date>2015-04-16T14:20:07Z</dc:date>
    </item>
    <item>
      <title>Re: Join tables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Join-tables/m-p/197097#M49237</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try this to attach the value of MAX(PWPUMAS) by each IN_PUMA_ID group:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;/P&gt;&lt;P&gt;&amp;nbsp; create table new as&lt;/P&gt;&lt;P&gt;&amp;nbsp; select A.*, MPWPUMAS as PWPUMAS &lt;/P&gt;&lt;P&gt;&amp;nbsp; from Agearank A &lt;/P&gt;&lt;P&gt;&amp;nbsp; left join &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; (select distinct IN_PUMA_ID, MAX(PWPUMAS) as MPWPUMAS&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from Agea B&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; group by IN_PUMA_ID)&lt;/P&gt;&lt;P&gt;&amp;nbsp; on (A.IN_PUMA_ID = B.IN_PUMA_ID)&lt;/P&gt;&lt;P&gt;&amp;nbsp; order by 1;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CTorres&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Apr 2015 14:44:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Join-tables/m-p/197097#M49237</guid>
      <dc:creator>CTorres</dc:creator>
      <dc:date>2015-04-16T14:44:07Z</dc:date>
    </item>
    <item>
      <title>Re: Join tables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Join-tables/m-p/197098#M49238</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;WHICH value of PWPUMAS do you want from the second table? Your example data shows ID 0100100 with values of 300 and 0? What is the rule for selecting the single value of PWPUMAS from Agea when there are multiple values?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Apr 2015 14:45:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Join-tables/m-p/197098#M49238</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2015-04-16T14:45:41Z</dc:date>
    </item>
    <item>
      <title>Re: Join tables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Join-tables/m-p/197099#M49239</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;Thank you for your reply. &lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;Suppose &lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 13px; background-color: #ffffff;"&gt;PWPUMAS with values of 0 means the data are missing for those observations and let's assume we have deleted them from the dataset "Agea". Accordingly, each observation's &lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 13px; background-color: #ffffff;"&gt;PWPUMAS would have a unique value. If this is the case, how to write the SAS code for the question I asked? Thanks!&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;Cheers,&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;Michael&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 18 Apr 2015 00:17:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Join-tables/m-p/197099#M49239</guid>
      <dc:creator>MichaelLin</dc:creator>
      <dc:date>2015-04-18T00:17:35Z</dc:date>
    </item>
    <item>
      <title>Re: Join tables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Join-tables/m-p/197100#M49240</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The same code works OK with the new supposition: if all values of PWPUMAS are the same then MAX(PWPUMAS) is this value for each IN_PUMA_ID&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can also use the following code assuming both files are sorted by IN_PUMA_ID and PWPUMAS has the same value for each IN_PUMA_ID:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Data new;&lt;/P&gt;&lt;P&gt;&amp;nbsp; merge Agearank (in=in_rank) Agea (keep=IN_PUMA_ID PWPUMAS);&lt;/P&gt;&lt;P&gt;&amp;nbsp; by IN_PUMA_ID;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if in_rank;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CTorres&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 Apr 2015 19:48:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Join-tables/m-p/197100#M49240</guid>
      <dc:creator>CTorres</dc:creator>
      <dc:date>2015-04-23T19:48:45Z</dc:date>
    </item>
  </channel>
</rss>

