<?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: Merging based on a large number of conditions in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Merging-based-on-a-large-number-of-conditions/m-p/167936#M263959</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I've run a few coding variations (inclusive Pierre's one) using fullstimer. The results were not conclusive and you will have to test with your real data.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What I don't understand: You say the relationships between your tables are "one to many" and this is also the case in the test data provided. In your real data: Couldn't it be that over time a patient has more than one condition? If so then the relationship would be many to many.&lt;/P&gt;&lt;P&gt;Eg. you give us this row in the condition data set: "3 2 . .". Does this mean that the "2" won't be used anywhere else, eg. for something like "3 2 . 6" ?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You're having "time" in your condition data set. In case it's many to many and you would only want to pick the latest matching condition then a data step approach would beat any SQL as you could stop comparisons as soon as there is a match (having the condition dataset sorted by descending time).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;About the 20 factors and typing: You could always write a little macro which generates the repetitive code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And here the code variations. On my laptop there is not really a clear "winner" - but as said: This might look very different when running stuff with real data.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;options fullstimer;&lt;/P&gt;&lt;P&gt;data condition;&lt;BR /&gt;&amp;nbsp; input time one two three;&lt;BR /&gt;&amp;nbsp; datalines;&lt;BR /&gt;1 3 4 5&lt;BR /&gt;2 . 6 8&lt;BR /&gt;3 2 . .&lt;BR /&gt;4 9 6 .&lt;BR /&gt;;;;;&lt;/P&gt;&lt;P&gt;data source;&lt;BR /&gt;&amp;nbsp; do number_client=1 to 1000000;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; one=ceil(ranuni(1)*9);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; two=ceil(ranuni(1)*9);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; three=ceil(ranuni(1)*9);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;BR /&gt;&amp;nbsp; end;&lt;BR /&gt;&amp;nbsp; stop;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* variant 1&amp;nbsp; */&lt;BR /&gt;proc sql feedback;&lt;BR /&gt;&amp;nbsp; create table want1 as&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; select &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a.time,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a.one as a_one, b.one as b_one,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a.two as a_two, b.two as b_two,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a.three as a_three, b.three as b_three,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; b.number_client &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; from condition as a left join source as b&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; on (a.one = b.one or a.one is null)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; and (a.two = b.two or a.two is null)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; and (a.three = b.three or a.three is null)&lt;BR /&gt;&amp;nbsp; ;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* variant 2&amp;nbsp; */&lt;BR /&gt;proc sql feedback;&lt;BR /&gt;&amp;nbsp; create table want2 as&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; select &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a.time,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a.one as a_one, b.one as b_one,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a.two as a_two, b.two as b_two,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a.three as a_three, b.three as b_three,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; b.number_client &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; from condition as a left join source as b&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; on (&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; b.one =coalesce(a.one,b.one)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; and b.two =coalesce(a.two,b.two)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; and b.three =coalesce(a.three,b.three)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; )&lt;BR /&gt;&amp;nbsp; ;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* variant 3&amp;nbsp; */&lt;BR /&gt;sasfile work.condition load; &lt;/P&gt;&lt;P&gt;data want3(drop=_:);&lt;BR /&gt;&amp;nbsp; set source&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; (rename=(one=_one two=_two three=_three))&lt;BR /&gt;&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do _i=1 to nobs;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set condition nobs=nobs point=_i;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _one =coalesce(one,_one)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; and _two =coalesce(two,_two)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; and _three =coalesce(three,_three) then&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;BR /&gt;&amp;nbsp; end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;sasfile work.condition close; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* variant 4&amp;nbsp; */&lt;BR /&gt;data condList(keep=time i item);&lt;BR /&gt;&amp;nbsp; set condition;&lt;BR /&gt;&amp;nbsp; array items{*} one -- three;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do i = 1 to dim(items);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; item = items{i};&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if not missing(item) then&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;BR /&gt;&amp;nbsp; end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data sourceList(keep=number_client i item);&lt;BR /&gt;&amp;nbsp; set source;&lt;BR /&gt;&amp;nbsp; array items{*} one -- three;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do i = 1 to dim(items);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; item = items{i};&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;BR /&gt;&amp;nbsp; end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;&amp;nbsp; create table timeClient as&lt;/P&gt;&lt;P&gt;&amp;nbsp; select time, number_client&lt;/P&gt;&lt;P&gt;&amp;nbsp; from &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; condList as a inner join &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; sourceList as b on a.i=b.i&lt;/P&gt;&lt;P&gt;&amp;nbsp; group by time, number_client&lt;/P&gt;&lt;P&gt;&amp;nbsp; having min(a.item=b.item)=1;&lt;BR /&gt;&amp;nbsp; create table want as&lt;/P&gt;&lt;P&gt;&amp;nbsp; select c.*, number_client &lt;/P&gt;&lt;P&gt;&amp;nbsp; from condition as c natural left join timeClient;&lt;BR /&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 09 Feb 2014 01:35:31 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2014-02-09T01:35:31Z</dc:date>
    <item>
      <title>Merging based on a large number of conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-based-on-a-large-number-of-conditions/m-p/167934#M263957</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Good morning,&lt;/P&gt;&lt;P&gt;I have to merge 2 datasets (one-to-many) on a long list of condition, more than 20 factors. So if I have to use Proc SQL, the section of "ON a.var=b.var" will be very long.&lt;/P&gt;&lt;P&gt;I wonder if there is any better way to do the merge both in terms of the code and the speed.&lt;/P&gt;&lt;P&gt;Many thanks,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;JHN&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data condition;&lt;BR /&gt;input time one two three ;&lt;BR /&gt;datalines;&lt;BR /&gt;1 3 4 5&lt;BR /&gt;2 . 6 8&lt;BR /&gt;3 2 . .&lt;BR /&gt;4 9 6 .&lt;BR /&gt;;;;;&lt;/P&gt;&lt;P&gt;data source;&lt;BR /&gt;input number_client one two three ;&lt;BR /&gt;datalines;&lt;BR /&gt;7 3 4 5&lt;BR /&gt;8 3 6 8&lt;BR /&gt;9 2 5 6&lt;BR /&gt;10 2 6 9&lt;BR /&gt;11 3 6 8&lt;BR /&gt;12 3 6 9&lt;BR /&gt;;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table want&lt;BR /&gt;as select * from condition as a left join source as b&lt;BR /&gt;on (a.one = b.one or a.one is null)&lt;BR /&gt;and (a.two = b.two or a.two is null)&lt;BR /&gt;and (a.three = b.three or a.three is null)&lt;BR /&gt;; quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 08 Feb 2014 16:47:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-based-on-a-large-number-of-conditions/m-p/167934#M263957</guid>
      <dc:creator>JMD</dc:creator>
      <dc:date>2014-02-08T16:47:52Z</dc:date>
    </item>
    <item>
      <title>Re: Merging based on a large number of conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-based-on-a-large-number-of-conditions/m-p/167935#M263958</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Joining on OR conditions is always problematic. You could try going from wide to long before the query :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data condition;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;input time one two three ;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;datalines;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;1 3 4 5&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;2 . 6 8&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;3 2 . .&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;4 9 6 .&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data source;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;input client one two three ;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;datalines;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;7 3 4 5&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;8 3 6 8&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;9 2 5 6&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;10 2 6 9&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;11 3 6 8&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;12 3 6 9&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data condList(keep=time i item);&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;set condition;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;array items{*} one -- three;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;do i = 1 to dim(items);&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; item = items{i};&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; if not missing(item) then output;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; end;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data sourceList(keep=client i item);&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;set source;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;array items{*} one -- three;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;do i = 1 to dim(items);&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; item = items{i};&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; output;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; end;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc sql;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;create table timeClient as&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;select time, client&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;from &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; condList as a inner join &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; sourceList as b on a.i=b.i&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;group by time, client&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;having min(a.item=b.item)=1;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;create table want as&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;select c.*, client &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;from condition as c natural left join timeClient;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;quit;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 08 Feb 2014 19:30:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-based-on-a-large-number-of-conditions/m-p/167935#M263958</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2014-02-08T19:30:02Z</dc:date>
    </item>
    <item>
      <title>Re: Merging based on a large number of conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-based-on-a-large-number-of-conditions/m-p/167936#M263959</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I've run a few coding variations (inclusive Pierre's one) using fullstimer. The results were not conclusive and you will have to test with your real data.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What I don't understand: You say the relationships between your tables are "one to many" and this is also the case in the test data provided. In your real data: Couldn't it be that over time a patient has more than one condition? If so then the relationship would be many to many.&lt;/P&gt;&lt;P&gt;Eg. you give us this row in the condition data set: "3 2 . .". Does this mean that the "2" won't be used anywhere else, eg. for something like "3 2 . 6" ?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You're having "time" in your condition data set. In case it's many to many and you would only want to pick the latest matching condition then a data step approach would beat any SQL as you could stop comparisons as soon as there is a match (having the condition dataset sorted by descending time).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;About the 20 factors and typing: You could always write a little macro which generates the repetitive code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And here the code variations. On my laptop there is not really a clear "winner" - but as said: This might look very different when running stuff with real data.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;options fullstimer;&lt;/P&gt;&lt;P&gt;data condition;&lt;BR /&gt;&amp;nbsp; input time one two three;&lt;BR /&gt;&amp;nbsp; datalines;&lt;BR /&gt;1 3 4 5&lt;BR /&gt;2 . 6 8&lt;BR /&gt;3 2 . .&lt;BR /&gt;4 9 6 .&lt;BR /&gt;;;;;&lt;/P&gt;&lt;P&gt;data source;&lt;BR /&gt;&amp;nbsp; do number_client=1 to 1000000;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; one=ceil(ranuni(1)*9);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; two=ceil(ranuni(1)*9);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; three=ceil(ranuni(1)*9);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;BR /&gt;&amp;nbsp; end;&lt;BR /&gt;&amp;nbsp; stop;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* variant 1&amp;nbsp; */&lt;BR /&gt;proc sql feedback;&lt;BR /&gt;&amp;nbsp; create table want1 as&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; select &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a.time,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a.one as a_one, b.one as b_one,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a.two as a_two, b.two as b_two,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a.three as a_three, b.three as b_three,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; b.number_client &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; from condition as a left join source as b&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; on (a.one = b.one or a.one is null)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; and (a.two = b.two or a.two is null)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; and (a.three = b.three or a.three is null)&lt;BR /&gt;&amp;nbsp; ;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* variant 2&amp;nbsp; */&lt;BR /&gt;proc sql feedback;&lt;BR /&gt;&amp;nbsp; create table want2 as&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; select &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a.time,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a.one as a_one, b.one as b_one,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a.two as a_two, b.two as b_two,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a.three as a_three, b.three as b_three,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; b.number_client &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; from condition as a left join source as b&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; on (&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; b.one =coalesce(a.one,b.one)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; and b.two =coalesce(a.two,b.two)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; and b.three =coalesce(a.three,b.three)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; )&lt;BR /&gt;&amp;nbsp; ;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* variant 3&amp;nbsp; */&lt;BR /&gt;sasfile work.condition load; &lt;/P&gt;&lt;P&gt;data want3(drop=_:);&lt;BR /&gt;&amp;nbsp; set source&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; (rename=(one=_one two=_two three=_three))&lt;BR /&gt;&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do _i=1 to nobs;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set condition nobs=nobs point=_i;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _one =coalesce(one,_one)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; and _two =coalesce(two,_two)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; and _three =coalesce(three,_three) then&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;BR /&gt;&amp;nbsp; end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;sasfile work.condition close; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* variant 4&amp;nbsp; */&lt;BR /&gt;data condList(keep=time i item);&lt;BR /&gt;&amp;nbsp; set condition;&lt;BR /&gt;&amp;nbsp; array items{*} one -- three;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do i = 1 to dim(items);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; item = items{i};&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if not missing(item) then&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;BR /&gt;&amp;nbsp; end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data sourceList(keep=number_client i item);&lt;BR /&gt;&amp;nbsp; set source;&lt;BR /&gt;&amp;nbsp; array items{*} one -- three;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do i = 1 to dim(items);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; item = items{i};&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;BR /&gt;&amp;nbsp; end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;&amp;nbsp; create table timeClient as&lt;/P&gt;&lt;P&gt;&amp;nbsp; select time, number_client&lt;/P&gt;&lt;P&gt;&amp;nbsp; from &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; condList as a inner join &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; sourceList as b on a.i=b.i&lt;/P&gt;&lt;P&gt;&amp;nbsp; group by time, number_client&lt;/P&gt;&lt;P&gt;&amp;nbsp; having min(a.item=b.item)=1;&lt;BR /&gt;&amp;nbsp; create table want as&lt;/P&gt;&lt;P&gt;&amp;nbsp; select c.*, number_client &lt;/P&gt;&lt;P&gt;&amp;nbsp; from condition as c natural left join timeClient;&lt;BR /&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 09 Feb 2014 01:35:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-based-on-a-large-number-of-conditions/m-p/167936#M263959</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2014-02-09T01:35:31Z</dc:date>
    </item>
    <item>
      <title>Re: Merging based on a large number of conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-based-on-a-large-number-of-conditions/m-p/167937#M263960</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi PR and Patric.&lt;/P&gt;&lt;P&gt;Thank you for you help.&lt;/P&gt;&lt;P&gt;They work perfectly.&lt;/P&gt;&lt;P&gt;JHN&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 09 Feb 2014 01:46:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-based-on-a-large-number-of-conditions/m-p/167937#M263960</guid>
      <dc:creator>JMD</dc:creator>
      <dc:date>2014-02-09T01:46:55Z</dc:date>
    </item>
    <item>
      <title>Re: Merging based on a large number of conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-based-on-a-large-number-of-conditions/m-p/167938#M263961</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Theoretically, the join could also be based on the LIKE operator:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data condition;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;input time one two three ;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;datalines;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;1 3 4 5&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;2 . 6 8&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;3 2 . .&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;4 9 6 .&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data source;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;input client one two three ;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;datalines;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;7 3 4 5&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;8 3 6 8&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;9 2 5 6&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;10 2 6 9&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;11 3 6 8&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;12 3 6 9&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data condChar;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;set condition;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;length str $32;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;array items{*} one -- three;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;do i = 1 to dim(items);&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; if missing(items{i}) then &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; substr(str,i,1) = "_";&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; else &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; substr(str,i,1) = put(items{i}, 1.);&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; end;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data sourceChar;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;set source;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;length str $32;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;array items{*} one -- three;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;do i = 1 to dim(items);&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; substr(str,i,1) = put(items{i}, 1.);&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; end;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc sql;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;create table want2 as&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;select a.*, b.client&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;from &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; condChar as a left join &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; sourceChar as b on b.str like a.str;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;quit;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But proc SQL warns that it cannot optimize this join.&lt;/P&gt;&lt;P&gt;PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 09 Feb 2014 02:52:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-based-on-a-large-number-of-conditions/m-p/167938#M263961</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2014-02-09T02:52:52Z</dc:date>
    </item>
    <item>
      <title>Re: Merging based on a large number of conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-based-on-a-large-number-of-conditions/m-p/167939#M263962</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If there are not too many different codes then you could also expand your condition table so that it contains all the combinations (and no more missings). This would then allow to use a hash lookup.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 09 Feb 2014 03:04:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-based-on-a-large-number-of-conditions/m-p/167939#M263962</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2014-02-09T03:04:20Z</dc:date>
    </item>
  </channel>
</rss>

