<?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: Appending and Merging in the same Data Step in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Appending-and-Merging-in-the-same-Data-Step/m-p/449175#M113020</link>
    <description>&lt;P&gt;Yes, you can do the same thing with a data step merge, but the three files would first have to be sorted. i.e.,&lt;/P&gt;
&lt;PRE&gt;proc sort data=individual;
  by Cust_ID;
run;

proc sort data=company;
  by Cust_ID;
run;

proc sort data=exist_check;
  by CN_ID;
run;

data want;
  merge individual
        company 
        exist_check (drop=Customer in=inC rename=(CN_ID=Cust_ID));
  by Cust_ID;
  if inC then CN_ID=Cust_ID;
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 27 Mar 2018 22:06:08 GMT</pubDate>
    <dc:creator>art297</dc:creator>
    <dc:date>2018-03-27T22:06:08Z</dc:date>
    <item>
      <title>Appending and Merging in the same Data Step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Appending-and-Merging-in-the-same-Data-Step/m-p/449162#M113015</link>
      <description>&lt;P&gt;I have three data sets and I want to append of two them on each other then join the appended datasets to a third data set. See code below for sample data and existing process. I would like to get the same result as the&amp;nbsp;&lt;FONT face="Courier New"&gt;Cust_ID_Check dataset in a single data step using the individual, company, and exist_check data sets.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; individual;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Record_ID Cust_ID &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;$5.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;datalines&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;35 AD123&lt;/P&gt;&lt;P&gt;74 NEW&lt;/P&gt;&lt;P&gt;24 GH456&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; company;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Record_ID Cust_ID &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;$5.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;datalines&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;21 YE789&lt;/P&gt;&lt;P&gt;62 AG&amp;amp;7&lt;/P&gt;&lt;P&gt;93 JI245&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; exist_check;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Customer &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;$4.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; CN_ID &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;$5.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;datalines&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sam AD123&lt;/P&gt;&lt;P&gt;Mia JI245&lt;/P&gt;&lt;P&gt;Jon YE789&lt;/P&gt;&lt;P&gt;Ben GH456&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;Data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; TEST;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; individual (&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;keep&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=Record_ID Cust_ID) company(&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;keep&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=Record_ID Cust_ID);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;sql&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;create&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;table&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Cust_ID_Check &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;as&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;select&lt;/FONT&gt; &lt;FONT color="#008080" face="Courier New" size="3"&gt;A.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;*, B.CN_ID&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;from&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; TEST &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;as&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; A&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;left&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;join&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; exist_check &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;as&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; B&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;on&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; (A.Cust_ID=B.CN_ID);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;quit&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Mar 2018 21:26:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Appending-and-Merging-in-the-same-Data-Step/m-p/449162#M113015</guid>
      <dc:creator>NW_SAS</dc:creator>
      <dc:date>2018-03-27T21:26:48Z</dc:date>
    </item>
    <item>
      <title>Re: Appending and Merging in the same Data Step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Appending-and-Merging-in-the-same-Data-Step/m-p/449175#M113020</link>
      <description>&lt;P&gt;Yes, you can do the same thing with a data step merge, but the three files would first have to be sorted. i.e.,&lt;/P&gt;
&lt;PRE&gt;proc sort data=individual;
  by Cust_ID;
run;

proc sort data=company;
  by Cust_ID;
run;

proc sort data=exist_check;
  by CN_ID;
run;

data want;
  merge individual
        company 
        exist_check (drop=Customer in=inC rename=(CN_ID=Cust_ID));
  by Cust_ID;
  if inC then CN_ID=Cust_ID;
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Mar 2018 22:06:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Appending-and-Merging-in-the-same-Data-Step/m-p/449175#M113020</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2018-03-27T22:06:08Z</dc:date>
    </item>
    <item>
      <title>Re: Appending and Merging in the same Data Step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Appending-and-Merging-in-the-same-Data-Step/m-p/449178#M113022</link>
      <description>&lt;P&gt;Hashes can make you avoid sort and accomplish in one datastep as you wanted:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data individual;

input Record_ID Cust_ID $5.;

datalines;
35 AD123
74 NEW
24 GH456
;

run;

 

data company;

input Record_ID Cust_ID $5.;

datalines;
21 YE789
62 AG&amp;amp;7
93 JI245
;

run;

 

data exist_check;

input Customer $4. CN_ID $5.;

datalines;
Sam AD123
Mia JI245
Jon YE789
Ben GH456
;

run;

data want;
if _n_=1 then do;
if 0 then do;set individual; set exist_check;end;
   dcl hash H (dataset:'exist_check') ;
   h.definekey  ("CN_ID") ;
   h.definedata ("CN_ID") ;
   h.definedone () ;
   end;
set individual company;
if h.find(key:Cust_ID) ne 0 then call missing(CN_ID);
drop customer;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Mar 2018 22:24:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Appending-and-Merging-in-the-same-Data-Step/m-p/449178#M113022</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-03-27T22:24:55Z</dc:date>
    </item>
  </channel>
</rss>

