<?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: Fetching only one  first transaction in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Fetching-only-one-first-transaction/m-p/889662#M351520</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
  select
    a.*,
    b.eff_date,
    b.trns_date
  from acct_details a left join payment_trns b
  on a.acct_no = b.acct_no and a.yearmonth = b.yearmonth and a.acct_status = "reactivated"
  group by a.acct_no, a.yearmonth
  having b.eff_date = min(b.eff_date)
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Untested, posted from my tablet.&lt;/P&gt;</description>
    <pubDate>Thu, 17 Aug 2023 14:02:29 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2023-08-17T14:02:29Z</dc:date>
    <item>
      <title>Fetching only one  first transaction</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fetching-only-one-first-transaction/m-p/889647#M351514</link>
      <description>&lt;P&gt;Hi I have two tables in sas,(&lt;STRONG&gt;acct_details&lt;/STRONG&gt; table) with columns&amp;nbsp;acct_no ,act_status and&amp;nbsp; yearmonth&lt;/P&gt;
&lt;P&gt;Table B( &lt;STRONG&gt;payment_trns&lt;/STRONG&gt; table) has columns:&amp;nbsp;yearmonth , trns_type,&amp;nbsp; acct_no , and eff_date&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to fetch the first transaction from&amp;nbsp;&lt;STRONG&gt;payment_trns(Only the trns_type, eff_date columns)&lt;/STRONG&gt; done in the same period the account was &lt;STRONG&gt;re-activated.&amp;nbsp;&lt;/STRONG&gt;I created the logic on the provided code&amp;nbsp; below code but i get incorrect results on the screenshot below the code&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data acct_details;
    format act_status $12.;
    input acct_no act_status $ yearmonth;
    datalines;
101 reactivated 202301
102 active 202301
103 reactivated 202302
103 reactivated 202303
;
run;

data payment_trns;
    informat EFF_DATE date9.;
    format EFF_DATE date9.;
    input yearmonth trns_type $ acct_no eff_date;
    datalines;
202301 TypeA 101 05JAN2023
202301 TypeB 101 10JAN2023
202302 TypeC 101 15FEB2023
202301 TypeA 102 07JAN2023
202301 TypeB 102 12JAN2023
202302 TypeA 103 03FEB2023
202302 TypeB 103 10FEB2023
202303 TypeD 103 11MAR2023
;
run;


proc sql;
    create table final_table as
    select A.*,
           B.eff_date,
           B.trns_type
    from acct_details as A
    left join (
        select yearmonth,
               acct_no,
               min(eff_date) as first_eff_date
        from payment_trns
        group by yearmonth, acct_no
    ) as  B_temp
    on A.yearmonth = B_temp.yearmonth and A.acct_no = B_temp.acct_no
    left join payment_trns as B
    on B_temp.yearmonth = B.yearmonth and B_temp.acct_no = B.acct_no 
    where A.act_status = 'reactivated';
quit;
&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Solly7_0-1692278357298.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/86765i89217E1D45D0D9BB/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Solly7_0-1692278357298.png" alt="Solly7_0-1692278357298.png" /&gt;&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;STRONG&gt;Data want&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;act_status&amp;nbsp; &amp;nbsp; &amp;nbsp; acct_no&amp;nbsp; &amp;nbsp; &amp;nbsp; yearmonth&amp;nbsp; EFF_DATE&amp;nbsp; &amp;nbsp; &amp;nbsp;trns_type&lt;BR /&gt;reactivated&amp;nbsp; &amp;nbsp; 101&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 202301&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 15JAN2023&amp;nbsp; &amp;nbsp; &amp;nbsp;TypeC&lt;BR /&gt;reactivated&amp;nbsp; &amp;nbsp;103&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 202302&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;03FEB2023&amp;nbsp; &amp;nbsp; &amp;nbsp;TypeA&lt;BR /&gt;reactivated&amp;nbsp; &amp;nbsp;103&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 202303&amp;nbsp; &amp;nbsp; &amp;nbsp; 11MAR2023&amp;nbsp; &amp;nbsp; &amp;nbsp;TypeD&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Aug 2023 13:21:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fetching-only-one-first-transaction/m-p/889647#M351514</guid>
      <dc:creator>Solly7</dc:creator>
      <dc:date>2023-08-17T13:21:16Z</dc:date>
    </item>
    <item>
      <title>Re: Fetching only one  first transaction</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fetching-only-one-first-transaction/m-p/889648#M351515</link>
      <description>&lt;P&gt;see above corrected desired results&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Data want&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;act_status&amp;nbsp; &amp;nbsp; &amp;nbsp; acct_no&amp;nbsp; &amp;nbsp; &amp;nbsp; yearmonth&amp;nbsp; EFF_DATE&amp;nbsp; &amp;nbsp; &amp;nbsp;trns_type&lt;BR /&gt;reactivated&amp;nbsp; &amp;nbsp; 101&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 202301&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 05JAN2023&amp;nbsp; &amp;nbsp; &amp;nbsp;TypeC&lt;BR /&gt;reactivated&amp;nbsp; &amp;nbsp;103&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 202302&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;03FEB2023&amp;nbsp; &amp;nbsp; &amp;nbsp;TypeA&lt;BR /&gt;reactivated&amp;nbsp; &amp;nbsp;103&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 202303&amp;nbsp; &amp;nbsp; &amp;nbsp; 11MAR2023&amp;nbsp; &amp;nbsp; &amp;nbsp;TypeD&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Aug 2023 13:24:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fetching-only-one-first-transaction/m-p/889648#M351515</guid>
      <dc:creator>Solly7</dc:creator>
      <dc:date>2023-08-17T13:24:20Z</dc:date>
    </item>
    <item>
      <title>Re: Fetching only one  first transaction</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fetching-only-one-first-transaction/m-p/889662#M351520</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
  select
    a.*,
    b.eff_date,
    b.trns_date
  from acct_details a left join payment_trns b
  on a.acct_no = b.acct_no and a.yearmonth = b.yearmonth and a.acct_status = "reactivated"
  group by a.acct_no, a.yearmonth
  having b.eff_date = min(b.eff_date)
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Untested, posted from my tablet.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Aug 2023 14:02:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fetching-only-one-first-transaction/m-p/889662#M351520</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-08-17T14:02:29Z</dc:date>
    </item>
    <item>
      <title>Re: Fetching only one  first transaction</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fetching-only-one-first-transaction/m-p/889673#M351521</link>
      <description>&lt;P&gt;Thanks a lot&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;, it works i just changed&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;and a.acct_status = "reactivated"&lt;/LI-CODE&gt;
&lt;P&gt;to&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;where a.acct_status = "reactivated"&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Aug 2023 14:13:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fetching-only-one-first-transaction/m-p/889673#M351521</guid>
      <dc:creator>Solly7</dc:creator>
      <dc:date>2023-08-17T14:13:03Z</dc:date>
    </item>
  </channel>
</rss>

