<?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 Join table with case when in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Join-table-with-case-when/m-p/847300#M335002</link>
    <description>&lt;P&gt;Hello Experts,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have two tables Acccount and Transaction and need create a new table that should have Account_ID, TotalCr, TotalDr and Balance.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Could you please help me to find the result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data account;&lt;BR /&gt;input Account_ID $ Name $ Accout_Type $ DateOfOpening date9.;&lt;BR /&gt;infile datalines dlm=',';&lt;BR /&gt;format DateOfOpening date9.;&lt;BR /&gt;datalines;&lt;BR /&gt;001,Tom,A,01Jan2010&lt;BR /&gt;002,Paul,T,01Feb2010&lt;BR /&gt;003,Sandy,A,01Jan2010&lt;BR /&gt;004,Sam,A,01Dec2018&lt;BR /&gt;005,Nancy,T,01Nov2010&lt;BR /&gt;006,Harry,A,01Jan2010&lt;BR /&gt;007,Rosy,A,01Jul2010&lt;BR /&gt;008,Mac,T,01Sep2010&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;data transaction;&lt;BR /&gt;input Account_ID $ Tr_Type $ Tr_Amount Date date9.;&lt;BR /&gt;infile datalines dlm=',';&lt;BR /&gt;format Date date9. Tr_Amount best32.;&lt;BR /&gt;datalines;&lt;BR /&gt;001,DR,1254,01Jan2010&lt;BR /&gt;002,CR,2546,01Feb2010&lt;BR /&gt;003,CR,5243,01Jan2010&lt;BR /&gt;004,DR,3654,01Dec2018&lt;BR /&gt;005,DR,7824,01Nov2010&lt;BR /&gt;006,CR,9587,01Jan2010&lt;BR /&gt;007,DR,6752,01Jul2010&lt;BR /&gt;008,CR,1578,01Sep2010&lt;BR /&gt;;&lt;BR /&gt;RUN;&lt;/P&gt;</description>
    <pubDate>Thu, 01 Dec 2022 17:59:02 GMT</pubDate>
    <dc:creator>Rahul_SAS</dc:creator>
    <dc:date>2022-12-01T17:59:02Z</dc:date>
    <item>
      <title>Join table with case when</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Join-table-with-case-when/m-p/847300#M335002</link>
      <description>&lt;P&gt;Hello Experts,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have two tables Acccount and Transaction and need create a new table that should have Account_ID, TotalCr, TotalDr and Balance.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Could you please help me to find the result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data account;&lt;BR /&gt;input Account_ID $ Name $ Accout_Type $ DateOfOpening date9.;&lt;BR /&gt;infile datalines dlm=',';&lt;BR /&gt;format DateOfOpening date9.;&lt;BR /&gt;datalines;&lt;BR /&gt;001,Tom,A,01Jan2010&lt;BR /&gt;002,Paul,T,01Feb2010&lt;BR /&gt;003,Sandy,A,01Jan2010&lt;BR /&gt;004,Sam,A,01Dec2018&lt;BR /&gt;005,Nancy,T,01Nov2010&lt;BR /&gt;006,Harry,A,01Jan2010&lt;BR /&gt;007,Rosy,A,01Jul2010&lt;BR /&gt;008,Mac,T,01Sep2010&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;data transaction;&lt;BR /&gt;input Account_ID $ Tr_Type $ Tr_Amount Date date9.;&lt;BR /&gt;infile datalines dlm=',';&lt;BR /&gt;format Date date9. Tr_Amount best32.;&lt;BR /&gt;datalines;&lt;BR /&gt;001,DR,1254,01Jan2010&lt;BR /&gt;002,CR,2546,01Feb2010&lt;BR /&gt;003,CR,5243,01Jan2010&lt;BR /&gt;004,DR,3654,01Dec2018&lt;BR /&gt;005,DR,7824,01Nov2010&lt;BR /&gt;006,CR,9587,01Jan2010&lt;BR /&gt;007,DR,6752,01Jul2010&lt;BR /&gt;008,CR,1578,01Sep2010&lt;BR /&gt;;&lt;BR /&gt;RUN;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Dec 2022 17:59:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Join-table-with-case-when/m-p/847300#M335002</guid>
      <dc:creator>Rahul_SAS</dc:creator>
      <dc:date>2022-12-01T17:59:02Z</dc:date>
    </item>
    <item>
      <title>Re: Join table with case when</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Join-table-with-case-when/m-p/847306#M335003</link>
      <description>&lt;P&gt;In this case, CASE WHEN is not necessary, I don't see a use for it here; and in fact its usually better to explain the input data (which you did) and show the desired output data, without specifying any particular coding method.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I didn't produce a column for balance, as it seems this is an imaginary variable that doesn't exist.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
    create table want as select
        a.account_id
        ,b.tr_type
        ,sum(b.tr_amount) as total
    from account as a left join transaction as b
        on a.account_id=b.account_id
    group by a.account_id,b.tr_type;
quit;

proc report data=want;
    columns account_id tr_type,total;
    define account_id/group;
    define tr_type/across;
    define total/sum;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Dec 2022 18:48:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Join-table-with-case-when/m-p/847306#M335003</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-12-01T18:48:46Z</dc:date>
    </item>
  </channel>
</rss>

