<?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 Merging by using proc sql with multiple conditions. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Merging-by-using-proc-sql-with-multiple-conditions/m-p/561248#M157083</link>
    <description>&lt;P&gt;I am trying to merge two dataset with multiple conditions, in proc sql but when both conditions fail it is giving me a cartisian product of the first variables in dataset with all other variables in second dataset. if any of the below two conditions doesnt match then i dont want to have cartesian product for that. i am getting a cartesian product with all the non matching record in first dataset getting merged with all the records for that subject in second dataset. I dont want that to happen is there any better to merge.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table pk_st_atr1 as&lt;BR /&gt;select st_atrx.*,pk_1x.adt,atm,pkstresc,pkstresu, case&lt;BR /&gt;when adt^= . then 'Y' end as pk_tr_fl&lt;BR /&gt;from st_atrx as X full join pk_1x as Y&lt;BR /&gt;on x.logdt ^= . and y.adt ^= . and x.logtm ^= . and y.atm ^= . and&lt;BR /&gt;(x.subject=y.subject and x.visitnum=y.visitnum and x.pktpt_std= y.pktpt_std and x.accession_number= y.accession_number and x.sample_id= y.sample_id)&lt;BR /&gt;or (x.subject=y.subject and x.visitnum=y.visitnum and x.accession_number= y.accession_number and x.sample_id= y.sample_id and x.logdt=y.adt and x.logtm=y.atm )&lt;BR /&gt;;&lt;BR /&gt;quit;&lt;BR /&gt;run;&lt;/P&gt;</description>
    <pubDate>Thu, 23 May 2019 21:43:15 GMT</pubDate>
    <dc:creator>yashraj89</dc:creator>
    <dc:date>2019-05-23T21:43:15Z</dc:date>
    <item>
      <title>Merging by using proc sql with multiple conditions.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-by-using-proc-sql-with-multiple-conditions/m-p/561248#M157083</link>
      <description>&lt;P&gt;I am trying to merge two dataset with multiple conditions, in proc sql but when both conditions fail it is giving me a cartisian product of the first variables in dataset with all other variables in second dataset. if any of the below two conditions doesnt match then i dont want to have cartesian product for that. i am getting a cartesian product with all the non matching record in first dataset getting merged with all the records for that subject in second dataset. I dont want that to happen is there any better to merge.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table pk_st_atr1 as&lt;BR /&gt;select st_atrx.*,pk_1x.adt,atm,pkstresc,pkstresu, case&lt;BR /&gt;when adt^= . then 'Y' end as pk_tr_fl&lt;BR /&gt;from st_atrx as X full join pk_1x as Y&lt;BR /&gt;on x.logdt ^= . and y.adt ^= . and x.logtm ^= . and y.atm ^= . and&lt;BR /&gt;(x.subject=y.subject and x.visitnum=y.visitnum and x.pktpt_std= y.pktpt_std and x.accession_number= y.accession_number and x.sample_id= y.sample_id)&lt;BR /&gt;or (x.subject=y.subject and x.visitnum=y.visitnum and x.accession_number= y.accession_number and x.sample_id= y.sample_id and x.logdt=y.adt and x.logtm=y.atm )&lt;BR /&gt;;&lt;BR /&gt;quit;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 23 May 2019 21:43:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-by-using-proc-sql-with-multiple-conditions/m-p/561248#M157083</guid>
      <dc:creator>yashraj89</dc:creator>
      <dc:date>2019-05-23T21:43:15Z</dc:date>
    </item>
    <item>
      <title>Re: Merging by using proc sql with multiple conditions.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-by-using-proc-sql-with-multiple-conditions/m-p/561287#M157106</link>
      <description>&lt;P&gt;Your code is a mess.&lt;/P&gt;
&lt;P&gt;Write legible code and the issue with your OR clause will become obvious.&lt;/P&gt;
&lt;P&gt;You might something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  create table PK_ST_ATR1 as
  select ST_ATRX.*
        ,PK_1X.ADT
        ,ATM
        ,PKSTRESC
        ,PKSTRESU
        ,case when ADT^= . then 'Y' end as PK_TR_FL
  from ST_ATRX as X 
         full join 
       PK_1X as Y
  on  x.LOGDT          ^= . 
  and y.ADT            ^= . 
  and x.LOGTM          ^= . 
  and y.ATM            ^= . 
  and x.SUBJECT         = y.SUBJECT 
  and x.VISITNUM        = y.VISITNUM 
  and x.ACCESSION_NUMBER= y.ACCESSION_NUMBER 
  and x.SAMPLE_ID       = y.SAMPLE_ID 
  and ( (x.PKTPT_STD    = y.PKTPT_STD )
      or(x.LOGDT=y.ADT and x.LOGTM=y.ATM ) )  ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Code should be pretty. This will make your life much easier.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, verify if:&lt;/P&gt;
&lt;P&gt;1. Do you really want a full join?&lt;/P&gt;
&lt;P&gt;2. Should the test on missing values be in a WHERE clause?&lt;/P&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>Fri, 24 May 2019 02:46:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-by-using-proc-sql-with-multiple-conditions/m-p/561287#M157106</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-05-24T02:46:09Z</dc:date>
    </item>
  </channel>
</rss>

