<?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: How to select observations in the whole sample based on a subsample ? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-select-observations-in-the-whole-sample-based-on-a/m-p/727092#M226070</link>
    <description>&lt;P&gt;You don't want a left join, you want an inner join:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table final as
select a.*
from have a, destination b
where a.gviidkey=b.gviidkey;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Do not select gviidkey from b, as it is already contained in a.*. This causes a WARNING.&lt;/P&gt;
&lt;P&gt;If you want to avoid any sorting, use a hash object:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
if _n_ = 1
then do;
  declare hash d (dataset:"destination");
  d.definekey("gviidkey");
  d.definedone();
end;
if d.check() = 0;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 17 Mar 2021 12:55:53 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2021-03-17T12:55:53Z</dc:date>
    <item>
      <title>How to select observations in the whole sample based on a subsample ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-select-observations-in-the-whole-sample-based-on-a/m-p/727081#M226068</link>
      <description>&lt;P&gt;Hi all SAS Users,&lt;/P&gt;
&lt;P&gt;I have the dataset &lt;STRONG&gt;have&lt;/STRONG&gt;:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;gviidkey	x1	    x2	ave_mar_cap
001166_01W	0	    3	    781881399.22
001166_02W	0	    3	    782818024.77
001166_01   0       3       59988888.13
001491_01W	0	    3	    211021885.49
001855_03W	0	    3	    7490455.1517
001932_01W	0	    3	    6966150208.8
001945_01W	0	    3	    3661586156.1
002162_01W	0	    3	    2576720.9485
002162_02W	0	    3	    2163731.9025
002338_01W	0	    3	    772042538.92
002410_01W	0	    3	    79948092816
002411_01W	0	    3	    33749159713
002411_03W	0	    3	    84226468905&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And I have the subsample dataset&lt;STRONG&gt; destination&lt;/STRONG&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;gviidkey	
001166_02W	
001491_01W	
001855_03W	
001932_01W	
002162_01W	
002338_01W	
002410_01W	
002411_03W&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What I want is dataset &lt;STRONG&gt;final&lt;/STRONG&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;gviidkey	x1		x2      ave_mar_cap
001166_02W	0	    3	    782818024.77
001491_01W	0	    3	    211021885.49
001855_03W	0	    3	    7490455.1517
001932_01W	0	    3	    6966150208.8
002162_01W	0	    3	    2576720.9485
002338_01W	0	    3	    772042538.92
002410_01W	0	    3	    79948092816
002411_03W	0	    3	    84226468905&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Can you please hint at me on how to sort it out?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Many thanks and warm regards.&lt;/P&gt;
&lt;P&gt;My novice code is&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create&amp;nbsp;table&amp;nbsp;final&amp;nbsp;as
select&amp;nbsp;a.*,&amp;nbsp;b.gviidkey
from&amp;nbsp;have&amp;nbsp;a&amp;nbsp;left&amp;nbsp;join&amp;nbsp;destination&amp;nbsp;b
on&amp;nbsp;a.gviidkey=b.gviidkey;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 Mar 2021 12:40:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-select-observations-in-the-whole-sample-based-on-a/m-p/727081#M226068</guid>
      <dc:creator>Phil_NZ</dc:creator>
      <dc:date>2021-03-17T12:40:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to select observations in the whole sample based on a subsample ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-select-observations-in-the-whole-sample-based-on-a/m-p/727092#M226070</link>
      <description>&lt;P&gt;You don't want a left join, you want an inner join:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table final as
select a.*
from have a, destination b
where a.gviidkey=b.gviidkey;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Do not select gviidkey from b, as it is already contained in a.*. This causes a WARNING.&lt;/P&gt;
&lt;P&gt;If you want to avoid any sorting, use a hash object:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
if _n_ = 1
then do;
  declare hash d (dataset:"destination");
  d.definekey("gviidkey");
  d.definedone();
end;
if d.check() = 0;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 Mar 2021 12:55:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-select-observations-in-the-whole-sample-based-on-a/m-p/727092#M226070</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-03-17T12:55:53Z</dc:date>
    </item>
  </channel>
</rss>

