select rows in a union based on a third table with proc
<p>I want to union the same table this way</p>

<pre><code>ID B C D E
1 11 12 13 14
2 21 22 23 24
3 31 32 33 34
</code></pre>

<p>to </p>

<pre><code>ID B C D E
1 11 12 13 14
2 21 22 23 24
3 31 32 33 34
11 13 14 
12
21 23 24
22
31 33 34
32
</code></pre>

<p>based on the IDs of a third table. (I want to have only those IDs which are present in a third table)</p>

<p>third table </p>

<pre><code>ID
1
3
21
31
</code></pre>

<p>I am able to do the union </p>

<pre><code>proc sql ; 
create table bb as 
select * from first 
union
select B, D, E from first
union
select C from first

;
quit; 
</code></pre>

<p>here is where I am stuck. how to select only those IDs present in a third table. </p>