<?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 proc sql  join with case when in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-join-with-case-when/m-p/378046#M276781</link>
    <description>&lt;P&gt;Hi SAS Experts,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am tryng to join two &amp;nbsp;tables based on cntry and num,&amp;nbsp;&lt;/P&gt;&lt;P&gt;and if a.value(from test1) &amp;gt; b.value(from test2) then i want to bring the "prct" from&lt;BR /&gt;test2 table ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data test1;&lt;BR /&gt;input cntry$ name$ value num;&lt;BR /&gt;datalines;&lt;BR /&gt;india abc 10 1&lt;BR /&gt;india ccf 11 2&lt;BR /&gt;us aba 22 3&lt;BR /&gt;china abca 20 4&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data test2;&lt;BR /&gt;input cntry$ value num prct;&lt;BR /&gt;datalines;&lt;BR /&gt;india 20 1 0.1&lt;BR /&gt;india 9 2 0.4&lt;BR /&gt;us 22 3 0.5&lt;BR /&gt;china 22 4 0.6&lt;BR /&gt;china 23 3 0.8&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my code and I think &amp;nbsp;this is not right. Please help&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Proc sql;&lt;BR /&gt;create table sample as&lt;BR /&gt;select a.Cntry,a.name,a.num,a.value from&lt;BR /&gt;test1 as a&lt;BR /&gt;case (when a.Cntry=b.cntry and a.num=b.num&lt;BR /&gt;and a.Value &amp;gt; b.value then prct end) as percentile1&lt;BR /&gt;left join test2 as b on a.Cntry=b.Cntry;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks &amp;amp; Regards,&lt;/P&gt;&lt;P&gt;Sanjay.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 21 Jul 2017 09:53:21 GMT</pubDate>
    <dc:creator>sanjay1</dc:creator>
    <dc:date>2017-07-21T09:53:21Z</dc:date>
    <item>
      <title>proc sql  join with case when</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-join-with-case-when/m-p/378046#M276781</link>
      <description>&lt;P&gt;Hi SAS Experts,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am tryng to join two &amp;nbsp;tables based on cntry and num,&amp;nbsp;&lt;/P&gt;&lt;P&gt;and if a.value(from test1) &amp;gt; b.value(from test2) then i want to bring the "prct" from&lt;BR /&gt;test2 table ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data test1;&lt;BR /&gt;input cntry$ name$ value num;&lt;BR /&gt;datalines;&lt;BR /&gt;india abc 10 1&lt;BR /&gt;india ccf 11 2&lt;BR /&gt;us aba 22 3&lt;BR /&gt;china abca 20 4&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data test2;&lt;BR /&gt;input cntry$ value num prct;&lt;BR /&gt;datalines;&lt;BR /&gt;india 20 1 0.1&lt;BR /&gt;india 9 2 0.4&lt;BR /&gt;us 22 3 0.5&lt;BR /&gt;china 22 4 0.6&lt;BR /&gt;china 23 3 0.8&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my code and I think &amp;nbsp;this is not right. Please help&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Proc sql;&lt;BR /&gt;create table sample as&lt;BR /&gt;select a.Cntry,a.name,a.num,a.value from&lt;BR /&gt;test1 as a&lt;BR /&gt;case (when a.Cntry=b.cntry and a.num=b.num&lt;BR /&gt;and a.Value &amp;gt; b.value then prct end) as percentile1&lt;BR /&gt;left join test2 as b on a.Cntry=b.Cntry;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks &amp;amp; Regards,&lt;/P&gt;&lt;P&gt;Sanjay.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jul 2017 09:53:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-join-with-case-when/m-p/378046#M276781</guid>
      <dc:creator>sanjay1</dc:creator>
      <dc:date>2017-07-21T09:53:21Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql  join with case when</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-join-with-case-when/m-p/378052#M276782</link>
      <description>&lt;P&gt;Yes, your putting select items in the join area. &amp;nbsp;Thats not how it should work. &amp;nbsp;Try (as I am guessing as you haven;t provided a required output):&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table SAMPLE as
  select  A.CNTRY,
          A.NAME,
          A.NUM,
          A.VALUE,
          case when A.VALUE &amp;gt; B.VALUE then PRCT else . end as PERCENTILE1      
  from    TEST1 A
  left join TEST2 B 
  on      A.CNTRY=B.CNTRY
  and     A.NUM=B.NUM;
quit;&lt;/PRE&gt;</description>
      <pubDate>Fri, 21 Jul 2017 10:02:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-join-with-case-when/m-p/378052#M276782</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-07-21T10:02:55Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql  join with case when</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-join-with-case-when/m-p/378328#M276783</link>
      <description>To be able verify that suggested solution meets your requirements, please provide an expected output data set.</description>
      <pubDate>Fri, 21 Jul 2017 21:05:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-join-with-case-when/m-p/378328#M276783</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2017-07-21T21:05:40Z</dc:date>
    </item>
  </channel>
</rss>

