title: Conditional join in SQL depending on a column value
body: <p>I'm trying to do a join on a SAS table using PROC-SQL. Depending on the value of one variable in table A I need to join using a column, otherwise I need to use another column.</p>
  
  <pre><code>proc sql;
  create table test
  as select
  A.*,
  A.PPNG_RVNE * B.perc_ress as variable1,
  A.P_RVNE    * B.perc_ress as variable2
  from      tableA    as A
  left join tableB    as B
  on case when A.cod_cia = 1 then A.cod_cia=B.cod_cia and A.cod_agrup_produto=B.cod_agrup_produto 
                             else A.cod_cia=B.cod_cia and A.projeto=B.projeto;
  </code></pre>
  
  <p>I need to join just to create variable1 and variable2. I don't want to select any variable from table B.</p>
  
  <p>My cod doesn't run. SAS gives me an error message saying that it is expecting an `end.</p>
  
  <p>Does anyone know how to conditional join depending on columns?</p>