<?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 merge two datasets? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-merge-two-datasets/m-p/603415#M76466</link>
    <description>&lt;P&gt;I do not comprehend your question.&amp;nbsp; Please provide sample data of the two data sets that you have, and sample data of what you want to produce.&lt;/P&gt;</description>
    <pubDate>Tue, 12 Nov 2019 01:37:20 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2019-11-12T01:37:20Z</dc:date>
    <item>
      <title>How to merge two datasets?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-merge-two-datasets/m-p/603413#M76465</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I merge two datasets where in first dataset I have only one variable &lt;EM&gt;city. &lt;/EM&gt;Second dataset contains two variables (without &lt;EM&gt;city&lt;/EM&gt; variable)- one of them was used to choose right values of &lt;EM&gt;city&lt;/EM&gt; variable:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;find(city, variable1)&amp;gt;0&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;How can I merge these datasets? By which variable and by which kind of join (inner/left/right)?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That's my input data:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;place&lt;/TD&gt;&lt;TD&gt;rate&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;london&lt;/TD&gt;&lt;TD&gt;15&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;paris&lt;/TD&gt;&lt;TD&gt;18&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;cracow&lt;/TD&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;city&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;cool_london&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;notknown&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;paris&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That's what I want to obtain:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;city&lt;/TD&gt;&lt;TD&gt;rate&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;cool_london&lt;/TD&gt;&lt;TD&gt;15&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;paris&lt;/TD&gt;&lt;TD&gt;18&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Tue, 12 Nov 2019 17:00:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-merge-two-datasets/m-p/603413#M76465</guid>
      <dc:creator>aaaaa34</dc:creator>
      <dc:date>2019-11-12T17:00:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to merge two datasets?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-merge-two-datasets/m-p/603415#M76466</link>
      <description>&lt;P&gt;I do not comprehend your question.&amp;nbsp; Please provide sample data of the two data sets that you have, and sample data of what you want to produce.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Nov 2019 01:37:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-merge-two-datasets/m-p/603415#M76466</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2019-11-12T01:37:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to merge two datasets?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-merge-two-datasets/m-p/603416#M76467</link>
      <description>I corrrect my post. Can you take a look?</description>
      <pubDate>Tue, 12 Nov 2019 01:59:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-merge-two-datasets/m-p/603416#M76467</guid>
      <dc:creator>aaaaa34</dc:creator>
      <dc:date>2019-11-12T01:59:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to merge two datasets?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-merge-two-datasets/m-p/603420#M76468</link>
      <description>"Second dataset contains three variables (without city variable)" Both input datasets you posted have less than three variables. Please post the source tables as is.</description>
      <pubDate>Tue, 12 Nov 2019 02:35:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-merge-two-datasets/m-p/603420#M76468</guid>
      <dc:creator>sustagens</dc:creator>
      <dc:date>2019-11-12T02:35:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to merge two datasets?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-merge-two-datasets/m-p/603425#M76469</link>
      <description>&lt;P&gt;If you know that you will never have more than one place found for any city, then this program would satisfy your objective.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
  input place :$10. rate;
datalines;
london 15
paris 18
cracow 10
run;

data two;
  input city :$15. ;
datalines;
cool_london
notknown
paris
run;

data want (drop=rc);
  if _n_=1 then do;
    if 0 then set one;
    declare hash d1 (dataset:'one');
     d1.definekey('place');
     d1.definedata('place','rate');
     d1.definedone();
    declare hiter i ('d1');
  end;
  set two;
  rc=i.first(); 
  do while (find(city,trim(place))=0 and rc=0);
    rc=i.next();      
  end;
  if rc=0;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;After establishing a lookup table base on ONE in the hash object D1, it reads each record in dataset TWO.&amp;nbsp; Then it iterates through D1 until a match is found, or the hash object is exhausted.&amp;nbsp; If the hash object is exhausted the return code variable RC is not a zero, and therefore you don't want an output record.&amp;nbsp; This can be relatively efficient because you tell the loop to stop with a successful FIND function (i.e. the FIND function returns a position number representing the character at which a successful match for PLACE has been found in CITY).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if you don't have many instances where an observations in TWO is never found in ONE, the above will be more efficient than the far simpler program below.&amp;nbsp; The below does a cartesian comparison of every obs in TWO against every obs in ONE, even after a match has been found.&amp;nbsp; Of course, this will discover instances in which a given PLACE is found in more than one CITY:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
  create table want2 as 
  select * from one inner join two
    on two.city like cats('%',one.place,'%') ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Nov 2019 04:05:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-merge-two-datasets/m-p/603425#M76469</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2019-11-12T04:05:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to merge two datasets?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-merge-two-datasets/m-p/603447#M76470</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/299214"&gt;@aaaaa34&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;Please have a look at below code and check whether this is what you are expecting.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data cityrate;
input place $6. rate;
datalines;
london	15
paris	18
cracow	10
;
run;
 
data city;
input place1 $11.;
datalines;
cool_london
notknown
paris
;
run;

 

data mergercity(keep=place1 rate) ;
merge cityrate(in=a) city(in=b)  ;


if a  and   b;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 12 Nov 2019 07:18:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-merge-two-datasets/m-p/603447#M76470</guid>
      <dc:creator>JJP1</dc:creator>
      <dc:date>2019-11-12T07:18:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to merge two datasets?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-merge-two-datasets/m-p/603463#M76471</link>
      <description>There should be two variables</description>
      <pubDate>Tue, 12 Nov 2019 10:10:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-merge-two-datasets/m-p/603463#M76471</guid>
      <dc:creator>aaaaa34</dc:creator>
      <dc:date>2019-11-12T10:10:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to merge two datasets?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-merge-two-datasets/m-p/603468#M76472</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/299214"&gt;@aaaaa34&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;i ran the whole code and final merge dataset is showing 2 variables only-got output&amp;nbsp; as below.please clearly suggest what you are expecting&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;rate place1&lt;BR /&gt;15 cool_london&lt;BR /&gt;18 notknown&lt;BR /&gt;10 paris&lt;/P&gt;</description>
      <pubDate>Tue, 12 Nov 2019 10:21:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-merge-two-datasets/m-p/603468#M76472</guid>
      <dc:creator>JJP1</dc:creator>
      <dc:date>2019-11-12T10:21:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to merge two datasets?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-merge-two-datasets/m-p/603613#M76474</link>
      <description>&lt;P&gt;Untested, you may need to tweak the FIND() function but it should work.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select t1.place, t1.rate, t2.city
from input_data as t1
cross join city_terms as t2
where find(t1.place, t2.city, 'i')&amp;gt;0;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/299214"&gt;@aaaaa34&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How can I merge two datasets where in first dataset I have only one variable &lt;EM&gt;city. &lt;/EM&gt;Second dataset contains three variables (without &lt;EM&gt;city&lt;/EM&gt; variable)- one of them was used to choose right values of &lt;EM&gt;city&lt;/EM&gt; variable:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;find(city, variable1)&amp;gt;0&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;How can I merge these datasets? By which variable and by which kind of join (inner/left/right)?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That's my input data:&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;place&lt;/TD&gt;
&lt;TD&gt;rate&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;london&lt;/TD&gt;
&lt;TD&gt;15&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;paris&lt;/TD&gt;
&lt;TD&gt;18&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;cracow&lt;/TD&gt;
&lt;TD&gt;10&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;city&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;cool_london&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;notknown&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;paris&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That's what I want to obtain:&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;city&lt;/TD&gt;
&lt;TD&gt;rate&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;cool_london&lt;/TD&gt;
&lt;TD&gt;15&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;paris&lt;/TD&gt;
&lt;TD&gt;18&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Nov 2019 16:23:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-merge-two-datasets/m-p/603613#M76474</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-11-12T16:23:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to merge two datasets?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-merge-two-datasets/m-p/603631#M76476</link>
      <description>I made a mistake, I edited my post.</description>
      <pubDate>Tue, 12 Nov 2019 17:01:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-merge-two-datasets/m-p/603631#M76476</guid>
      <dc:creator>aaaaa34</dc:creator>
      <dc:date>2019-11-12T17:01:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to merge two datasets?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-merge-two-datasets/m-p/603632#M76477</link>
      <description>Thank you &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/256123"&gt;@JJP1&lt;/a&gt; but I want to have only place1 with values of place (notknown doesn't contain them)</description>
      <pubDate>Tue, 12 Nov 2019 17:03:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-merge-two-datasets/m-p/603632#M76477</guid>
      <dc:creator>aaaaa34</dc:creator>
      <dc:date>2019-11-12T17:03:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to merge two datasets?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-merge-two-datasets/m-p/603633#M76478</link>
      <description>&lt;P&gt;Yes it worked. But is it possible to avoid find in proc sql (like using this function earlier)? And then merge city variable (right values) with rate? The problem is that I dont know how to merge this variables?&lt;/P&gt;</description>
      <pubDate>Tue, 12 Nov 2019 17:08:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-merge-two-datasets/m-p/603633#M76478</guid>
      <dc:creator>aaaaa34</dc:creator>
      <dc:date>2019-11-12T17:08:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to merge two datasets?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-merge-two-datasets/m-p/603645#M76481</link>
      <description>No, you cannot avoid using FIND() because it's not an exact match so you need a condition on the join. What's the issue with FIND()?</description>
      <pubDate>Tue, 12 Nov 2019 17:37:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-merge-two-datasets/m-p/603645#M76481</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-11-12T17:37:41Z</dc:date>
    </item>
  </channel>
</rss>

