<?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 Combine two datasets in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Combine-two-datasets/m-p/613669#M179243</link>
    <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;I am struggling to find a code that can help me combining two datasets i.e. one and two.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
 input X Y $ Z;
 datalines;
1 a 0.1
1 b 0.2
1 c 0.5
2 c 0.8
2 d 0.5
2 e 0.7
;


data two;
 input Y $ R;
 datalines;
a 5
b 6
c 9
d 7
e 2
f 4
;

data Want;
 input X Y $ Z R;
 datalines;
1 a 0.1 5
1 b 0.2 6
1 c 0.5 9
1 d . 7
1 e . 2
1 f . 4
2 a . 5
2 b . 6
2 c 0.8 9
2 d 0.5 7
2 e 0.7 2
2 f . 4
;

run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Kindly guide me in this regard.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Tue, 24 Dec 2019 03:16:46 GMT</pubDate>
    <dc:creator>Saba1</dc:creator>
    <dc:date>2019-12-24T03:16:46Z</dc:date>
    <item>
      <title>Combine two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-two-datasets/m-p/613669#M179243</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;I am struggling to find a code that can help me combining two datasets i.e. one and two.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
 input X Y $ Z;
 datalines;
1 a 0.1
1 b 0.2
1 c 0.5
2 c 0.8
2 d 0.5
2 e 0.7
;


data two;
 input Y $ R;
 datalines;
a 5
b 6
c 9
d 7
e 2
f 4
;

data Want;
 input X Y $ Z R;
 datalines;
1 a 0.1 5
1 b 0.2 6
1 c 0.5 9
1 d . 7
1 e . 2
1 f . 4
2 a . 5
2 b . 6
2 c 0.8 9
2 d 0.5 7
2 e 0.7 2
2 f . 4
;

run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Kindly guide me in this regard.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 24 Dec 2019 03:16:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-two-datasets/m-p/613669#M179243</guid>
      <dc:creator>Saba1</dc:creator>
      <dc:date>2019-12-24T03:16:46Z</dc:date>
    </item>
    <item>
      <title>Re: Combine two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-two-datasets/m-p/613674#M179246</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
 input X Y $ Z;
 datalines;
1 a 0.1
1 b 0.2
1 c 0.5
2 c 0.8
2 d 0.5
2 e 0.7
;


data two;
 input Y $ R;
 datalines;
a 5
b 6
c 9
d 7
e 2
f 4
;

data want ;
 if 0 then set one two;
   dcl hash H (dataset: "two") ;
   h.definekey  ("y") ;
   h.definedata ("y","r") ;
   h.definedone () ;
do until(last.x);
 set one;
 by x;
 if h.find() ne 0 then call missing(r);
 else h.remove();
 output;
end;
call missing(r,z);
dcl hiter hi('h');
do while(hi.next()=0);
 output;
end;
h.delete();
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 24 Dec 2019 04:24:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-two-datasets/m-p/613674#M179246</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-12-24T04:24:25Z</dc:date>
    </item>
    <item>
      <title>Re: Combine two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-two-datasets/m-p/613710#M179270</link>
      <description>&lt;P&gt;If you would like a simpler program, it can be (probably) done but requires an extra step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;&lt;BR /&gt;   create table XLIST as select distinct X from one;
   create table shell as select * from two, xlist order by x, y;
quit;

data want;
   merge shell one;
   by X Y;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;When I say "probably", note two things:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;This code is untested and my SQL syntax is rusty.&lt;/LI&gt;
&lt;LI&gt;The results rely on the data set ONE already being in sorted order.&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Tue, 24 Dec 2019 09:43:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-two-datasets/m-p/613710#M179270</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-12-24T09:43:38Z</dc:date>
    </item>
    <item>
      <title>Re: Combine two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-two-datasets/m-p/613721#M179279</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
 input X Y $ Z;
 datalines;
1 a 0.1
1 b 0.2
1 c 0.5
2 c 0.8
2 d 0.5
2 e 0.7
;


data two;
 input Y $ R;
 datalines;
a 5
b 6
c 9
d 7
e 2
f 4
;

proc sql;
create table want as
select a.*,z from
(select * from (select distinct x from one),two) as a
left join one as b on a.x=b.x and a.y=b.y
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 24 Dec 2019 11:48:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-two-datasets/m-p/613721#M179279</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-12-24T11:48:41Z</dc:date>
    </item>
  </channel>
</rss>

