<?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: sas proc sql and using a condition for the left join in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/sas-proc-sql-and-using-a-condition-for-the-left-join/m-p/419629#M26996</link>
    <description>&lt;P&gt;I am not sure I understand what your code is doing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tryed two consecutive join as below.&amp;nbsp; What do you think about that?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table provnbqt1&lt;BR /&gt;as select table1.*, table5.dtcreationVIP, table5.hrcreationVIP, table5.VIP,&lt;BR /&gt;table6.clicassure, datepart(table6.started) as dtcreationCLA format yymmdd10., timepart(table6.started) as hrcreationCLA format time8.,&lt;BR /&gt;table7.rentecoll, datepart(table7.started) as dtcreationRCO format yymmdd10., timepart(table7.started) as hrcreationRCO format time8.,&lt;BR /&gt;table8.web&lt;/P&gt;&lt;P&gt;FROM provnbqt as table1&lt;/P&gt;&lt;P&gt;left join ref_vip as table5&lt;BR /&gt;on table1.ACCOUNTNUMBER = table5.ACCOUNT_NUMBER and table1.dttrnsys = table5.dtcreationVIP&lt;/P&gt;&lt;P&gt;/*201607 CP je veux ajouter la provenace clic assure la note est au niveau account et on a un delai de 7 jours&lt;BR /&gt;admissible on associe que les soum on va passer par une provenance tempo pour les ventes*/&lt;BR /&gt;left join clicassure as table6&lt;BR /&gt;on table1.ACCOUNTNUMBER = table6.primaryentityid and datepart(table6.started)&amp;lt;=table1.dttrnsys&amp;lt;=sum(datepart(table6.started),7)/* and table1.type_lot="QT"*/&lt;/P&gt;&lt;P&gt;/*201609 CP je veux ajouter la provenace rente collective la note est au niveau account et on a un delai de 7 jours&lt;BR /&gt;admissible on associe que les soum on va passer par une provenance tempo pour les ventes*/&lt;BR /&gt;left join rente_coll as table7&lt;BR /&gt;on table1.ACCOUNTNUMBER = table7.primaryentityid and datepart(table7.started)&amp;lt;=table1.dttrnsys&amp;lt;=sum(datepart(table7.started),7) /*and table1.type_lot="QT"*/&lt;/P&gt;&lt;P&gt;left join SoumEnLigne (where=( PRIMARYENTITYCLASS eq "Quote")) as table8&lt;BR /&gt;on table1.POLICYNUMBER = table8.primaryentityid and&lt;BR /&gt;datepart(table8.started)&amp;lt;=table1.dttrnsys&amp;lt;=sum(datepart(table8.started),7)&lt;/P&gt;&lt;P&gt;left join SoumEnLigne (where =(PRIMARYENTITYCLASS eq "Account")) as table9&lt;BR /&gt;on table1.ACCOUNTNUMBER = table9.primaryentityid and&lt;BR /&gt;datepart(table9.started)&amp;lt;=table1.dttrnsys&amp;lt;=sum(datepart(table9.started),7) /*and table1.type_lot="QT"*/&lt;BR /&gt;&lt;BR /&gt;;&lt;BR /&gt;QUIT;&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 08 Dec 2017 17:06:55 GMT</pubDate>
    <dc:creator>alepage</dc:creator>
    <dc:date>2017-12-08T17:06:55Z</dc:date>
    <item>
      <title>sas proc sql and using a condition for the left join</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/sas-proc-sql-and-using-a-condition-for-the-left-join/m-p/419578#M26988</link>
      <description>&lt;P&gt;Asking the expert!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to make multiple left join in order to create a new table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;One of my table is SoumEnLigne as table8&lt;/P&gt;&lt;P&gt;In this table, I have the variable primaryidentityclass which could take only two values (quote or account)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Therefore based on the value of this variable I would like to make two different left join&lt;/P&gt;&lt;P&gt;ex:&lt;/P&gt;&lt;P&gt;case 1,&amp;nbsp;&lt;SPAN&gt;primaryidentityclass=quote then&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;on table1.POLICYNUMBER = table8.primaryentityid and&lt;BR /&gt;datepart(table8.started)&amp;lt;=table1.dttrnsys&amp;lt;=sum(datepart(table8.started),7) and table1.type_lot="QT";&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Case2,&amp;nbsp;primaryidentityclass=account then&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;n table1.ACCOUNTNUMBER = table8.primaryentityid and&lt;BR /&gt;datepart(table8.started)&amp;lt;=table1.dttrnsys&amp;lt;=sum(datepart(table8.started),7) and table1.type_lot="QT";&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;So if the primaryidentityclass eq quote the we compare the policynumber of table1 with the primaryidentityid of table8&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;if the primaryidentityclass eq&amp;nbsp;account the we compare the accountnumber of table1 with the primaryidentityid of table8&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;How can we do that ?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Here's a part of my log file&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;53 on table1.POLICYNUMBER = table8.primaryentityid and&lt;BR /&gt;54 datepart(table8.started)&amp;lt;=table1.dttrnsys&amp;lt;=sum(datepart(table8.started),7) and table1.type_lot="QT";&lt;BR /&gt;55 %end;&lt;BR /&gt;56&lt;BR /&gt;57 %if table8.primaryentityclass eq "Account" %then&lt;BR /&gt;58 %do;&lt;BR /&gt;59&lt;BR /&gt;60 on table1.ACCOUNTNUMBER = table8.primaryentityid and&lt;BR /&gt;61 datepart(table8.started)&amp;lt;=table1.dttrnsys&amp;lt;=sum(datepart(table8.started),7) and table1.type_lot="QT";&lt;BR /&gt;62&lt;BR /&gt;63 %end;&lt;BR /&gt;64 ;&lt;BR /&gt;65 QUIT;&lt;BR /&gt;66 %mend provbqt1;&lt;BR /&gt;67 %provbqt1;&lt;BR /&gt;MLOGIC(PROVBQT1): Début de l'exécution.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;MPRINT(PROVBQT1): proc sql;&lt;BR /&gt;MLOGIC(PROVBQT1) : La condition %IF table8.primaryentityclass eq "Quote" est FALSE&lt;BR /&gt;MLOGIC(PROVBQT1) : La condition %IF table8.primaryentityclass eq "Account" est FALSE&lt;BR /&gt;NOTE: Line generated by the invoked macro "PROVBQT1".&lt;BR /&gt;67 ;&lt;BR /&gt;_&lt;BR /&gt;73&lt;BR /&gt;76&lt;BR /&gt;MPRINT(PROVBQT1): create table provnbqt1 as select table1.*, table5.dtcreationVIP, table5.hrcreationVIP, table5.VIP,&lt;BR /&gt;table6.clicassure, datepart(table6.started) as dtcreationCLA format yymmdd10., timepart(table6.started) as hrcreationCLA format&lt;BR /&gt;time8., table7.rentecoll, datepart(table7.started) as dtcreationRCO format yymmdd10., timepart(table7.started) as hrcreationRCO&lt;BR /&gt;format time8., table8.web FROM provnbqt as table1 left join ref_vip as table5 on table1.ACCOUNTNUMBER = table5.ACCOUNT_NUMBER and&lt;BR /&gt;table1.dttrnsys = table5.dtcreationVIP left join clicassure as table6 on table1.ACCOUNTNUMBER = table6.primaryentityid and&lt;BR /&gt;datepart(table6.started)&amp;lt;=table1.dttrnsys&amp;lt;=sum(datepart(table6.started),7) and table1.type_lot="QT" left join rente_coll as table7&lt;BR /&gt;on table1.ACCOUNTNUMBER = table7.primaryentityid and datepart(table7.started)&amp;lt;=table1.dttrnsys&amp;lt;=sum(datepart(table7.started),7) and&lt;BR /&gt;table1.type_lot="QT" left join SoumEnLigne as table8 ;&lt;BR /&gt;ERROR 73-322: Expecting an ON.&lt;/P&gt;&lt;P&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;/P&gt;&lt;P&gt;NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.&lt;BR /&gt;MPRINT(PROVBQT1): QUIT;&lt;BR /&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;BR /&gt;NOTE: PROCEDURE SQL used (Total process time):&lt;/P&gt;</description>
      <pubDate>Fri, 08 Dec 2017 14:52:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/sas-proc-sql-and-using-a-condition-for-the-left-join/m-p/419578#M26988</guid>
      <dc:creator>alepage</dc:creator>
      <dc:date>2017-12-08T14:52:39Z</dc:date>
    </item>
    <item>
      <title>Re: sas proc sql and using a condition for the left join</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/sas-proc-sql-and-using-a-condition-for-the-left-join/m-p/419584#M26989</link>
      <description>&lt;P&gt;Why are you over complicating it?&amp;nbsp; You want to select xyz variable from have2 based on one merge, and abc variable from have2 based on second merge:&lt;/P&gt;
&lt;PRE&gt;proc sql;
  select A.*, &lt;BR /&gt;         B.B_QUOTE,
         B.XYZ,&lt;BR /&gt;         C.ACCOUNT,
         C.ABC,&lt;BR /&gt;         case when A.POLICY_NUMBER=B.B_QUOTE then "Cond1" else "" end as FLAG1,&lt;BR /&gt;         case when A.ACCOUNT_NUMBER=C.PRIMARY_ENTITY_ID then "Cond2" else "" end as FLAG2
  from   HAVE A
  left join (select MERGEVARS,QUOTE as B_QUOTE,XYZ from HAVE) B
  on        A.MERGEVARS=B.MERGEVARS
  left join (select MERGEVARS,ACCOUNT as C_ACCOUNT,ABC from HAVE) C
  on        A.MERGEVARS=B.MERGEVARS;
quit;&lt;/PRE&gt;
&lt;P&gt;So your effectively creating variables for what is in the joins rather than trying to conditionally merge.&amp;nbsp; Also, you would most likely get a better response to questions, by&amp;nbsp;&lt;U&gt;&lt;STRONG&gt;providing test data in the form of a datastep, an what you want to see at the end.&lt;/STRONG&gt;&lt;/U&gt;&amp;nbsp; Showing a small snippet of some code with macros and what not going on does not help anyone, neither does a mass of cODe wH%cH lOKKS L%ke thiS.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Dec 2017 15:10:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/sas-proc-sql-and-using-a-condition-for-the-left-join/m-p/419584#M26989</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-12-08T15:10:23Z</dc:date>
    </item>
    <item>
      <title>Re: sas proc sql and using a condition for the left join</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/sas-proc-sql-and-using-a-condition-for-the-left-join/m-p/419629#M26996</link>
      <description>&lt;P&gt;I am not sure I understand what your code is doing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tryed two consecutive join as below.&amp;nbsp; What do you think about that?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table provnbqt1&lt;BR /&gt;as select table1.*, table5.dtcreationVIP, table5.hrcreationVIP, table5.VIP,&lt;BR /&gt;table6.clicassure, datepart(table6.started) as dtcreationCLA format yymmdd10., timepart(table6.started) as hrcreationCLA format time8.,&lt;BR /&gt;table7.rentecoll, datepart(table7.started) as dtcreationRCO format yymmdd10., timepart(table7.started) as hrcreationRCO format time8.,&lt;BR /&gt;table8.web&lt;/P&gt;&lt;P&gt;FROM provnbqt as table1&lt;/P&gt;&lt;P&gt;left join ref_vip as table5&lt;BR /&gt;on table1.ACCOUNTNUMBER = table5.ACCOUNT_NUMBER and table1.dttrnsys = table5.dtcreationVIP&lt;/P&gt;&lt;P&gt;/*201607 CP je veux ajouter la provenace clic assure la note est au niveau account et on a un delai de 7 jours&lt;BR /&gt;admissible on associe que les soum on va passer par une provenance tempo pour les ventes*/&lt;BR /&gt;left join clicassure as table6&lt;BR /&gt;on table1.ACCOUNTNUMBER = table6.primaryentityid and datepart(table6.started)&amp;lt;=table1.dttrnsys&amp;lt;=sum(datepart(table6.started),7)/* and table1.type_lot="QT"*/&lt;/P&gt;&lt;P&gt;/*201609 CP je veux ajouter la provenace rente collective la note est au niveau account et on a un delai de 7 jours&lt;BR /&gt;admissible on associe que les soum on va passer par une provenance tempo pour les ventes*/&lt;BR /&gt;left join rente_coll as table7&lt;BR /&gt;on table1.ACCOUNTNUMBER = table7.primaryentityid and datepart(table7.started)&amp;lt;=table1.dttrnsys&amp;lt;=sum(datepart(table7.started),7) /*and table1.type_lot="QT"*/&lt;/P&gt;&lt;P&gt;left join SoumEnLigne (where=( PRIMARYENTITYCLASS eq "Quote")) as table8&lt;BR /&gt;on table1.POLICYNUMBER = table8.primaryentityid and&lt;BR /&gt;datepart(table8.started)&amp;lt;=table1.dttrnsys&amp;lt;=sum(datepart(table8.started),7)&lt;/P&gt;&lt;P&gt;left join SoumEnLigne (where =(PRIMARYENTITYCLASS eq "Account")) as table9&lt;BR /&gt;on table1.ACCOUNTNUMBER = table9.primaryentityid and&lt;BR /&gt;datepart(table9.started)&amp;lt;=table1.dttrnsys&amp;lt;=sum(datepart(table9.started),7) /*and table1.type_lot="QT"*/&lt;BR /&gt;&lt;BR /&gt;;&lt;BR /&gt;QUIT;&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Dec 2017 17:06:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/sas-proc-sql-and-using-a-condition-for-the-left-join/m-p/419629#M26996</guid>
      <dc:creator>alepage</dc:creator>
      <dc:date>2017-12-08T17:06:55Z</dc:date>
    </item>
  </channel>
</rss>

