<?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: Historical data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Historical-data/m-p/853965#M337529</link>
    <description>&lt;P&gt;Nope, In simple note - I just want the customers who took new savings account in Oct'22. But we have two cases-&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data NTBSAV OTHSAV;&lt;/P&gt;&lt;P&gt;SET TEST;&lt;/P&gt;&lt;P&gt;??????&lt;/P&gt;&lt;P&gt;????&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;NTBSAV dataset- Customer who is NTB(New to Business - first entry historically) and took savings account in Oct'22 [Cust ID: 2000&amp;nbsp; should be reported]&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;OTHSAV dataset- Customer took savings account in Oct'22 but not NTB, since he/she already NTB through loan product. [Cust id 1000 should be reported]&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Note -&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;#1. We have to analyze historically other products and previous months entries as well.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;#2. Cust Id:3000 should not be reported in both the datasets.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sample data below:-&lt;/P&gt;&lt;P&gt;data test;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;infile datalines;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;input cus year month NTB ca_ind sav_ind loan_ind;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;1000 2022 08 1 0 0 1&lt;BR /&gt;1000 2022 09 0 0 0 1&lt;BR /&gt;1000 2022 10 0 0 1 1&lt;/P&gt;&lt;P&gt;3000 2022 08 1 1 1 0&lt;BR /&gt;3000 2022 09 0 1 1 0&lt;BR /&gt;3000 2022 10 0 1 1 0&lt;BR /&gt;2000 2022 08 0 0 0 0&lt;BR /&gt;2000 2022 09 0 0 0 0&lt;BR /&gt;2000 2022 10 1 0 1 0&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;</description>
    <pubDate>Mon, 16 Jan 2023 10:33:14 GMT</pubDate>
    <dc:creator>AshokD</dc:creator>
    <dc:date>2023-01-16T10:33:14Z</dc:date>
    <item>
      <title>Historical data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Historical-data/m-p/853933#M337517</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've a sample data below:-&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;data test;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;infile datalines;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;input cus year month NTB ca_ind sav_ind loan_ind;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;datalines;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;1000 2022 08 1 0 0 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1000 2022 09 0 0 0 1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;1000 2022 10 0 0 1 1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2000 2022 08 0 0 0 0&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2000 2022 09 0 0 0 0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2000 2022 10 1 0 1 0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I have two cases now:-&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;#1. To find the customers who took the savings account through NTB in the oct'22 month.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;#2.To find the customers who took the savings account but not through NTB in the oct'22 month.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;proc sort data =test; by cus year month;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;data NTBSAV OTHSAV;&lt;/P&gt;&lt;P&gt;set&amp;nbsp;&lt;SPAN&gt;test;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;by&amp;nbsp;cus;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;if first.cus and NTB = 1 AND&amp;nbsp;sav_ind = 1 THEN OUTPUT NTBSAV ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;RUN;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;#1. This logic is working fine. cus id =&amp;nbsp;2000 is reported in NTBSAV&amp;nbsp; dataset.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;#2.&amp;nbsp; Actually in OTHSAV dataset cus id =1000&amp;nbsp; should be reported. But I'm not sure about the logic Since I need to check historically for NTB field and other products indicator as well.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Could someone of you please help me here ?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks in advance.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 15 Jan 2023 19:50:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Historical-data/m-p/853933#M337517</guid>
      <dc:creator>AshokD</dc:creator>
      <dc:date>2023-01-15T19:50:03Z</dc:date>
    </item>
    <item>
      <title>Re: Historical data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Historical-data/m-p/853934#M337518</link>
      <description>&lt;P&gt;Is this what you want??&lt;/P&gt;
&lt;P&gt;( question is not fully clear to me )&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
infile datalines;
input cus year month NTB ca_ind sav_ind loan_ind;
datum=MDY(month,15,year);
format datum ddmmyy10.;
datalines;
1000 2022 08 1 0 0 1
1000 2022 09 0 0 0 1
1000 2022 10 0 0 1 1
2000 2022 08 0 0 0 0
2000 2022 09 0 0 0 0
2000 2022 10 1 0 1 0
;
run;

data took_sav_throughNTB_oct22;
 set test;
 where datum = '15OCT2022'd;
 if (NTB=1 AND sav_ind=1) then output;
run;

data took_sav_NOTthroughNTB_oct22;
 set test;
 where datum = '15OCT2022'd;
 if (NTB=0 AND sav_ind=1) then output;
run;
/* end of program */&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Sun, 15 Jan 2023 21:08:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Historical-data/m-p/853934#M337518</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2023-01-15T21:08:36Z</dc:date>
    </item>
    <item>
      <title>Re: Historical data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Historical-data/m-p/853935#M337519</link>
      <description>&lt;P&gt;Or rather like this (with one data step only!) :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
infile datalines;
input cus year month NTB ca_ind sav_ind loan_ind;
datum=MDY(month,15,year);
format datum ddmmyy10.;
datalines;
1000 2022 08 1 0 0 1
1000 2022 09 0 0 0 1
1000 2022 10 0 0 1 1
2000 2022 08 0 0 0 0
2000 2022 09 0 0 0 0
2000 2022 10 1 0 1 0
;
run;

data took_sav_throughNTB_oct22
     took_sav_NOTthroughNTB_oct22;
 set test;
 where datum = '15OCT2022'd;
 if      (NTB=1 AND sav_ind=1) then output took_sav_throughNTB_oct22;
 else if (NTB=0 AND sav_ind=1) then output took_sav_NOTthroughNTB_oct22;
 else;
run;
/* end of program */&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Sun, 15 Jan 2023 21:11:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Historical-data/m-p/853935#M337519</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2023-01-15T21:11:04Z</dc:date>
    </item>
    <item>
      <title>Re: Historical data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Historical-data/m-p/853947#M337523</link>
      <description>&lt;P&gt;Apologies, Let me make it more clear with the below data sample:-&lt;/P&gt;&lt;P&gt;datalines;&lt;BR /&gt;1000 2022 08 1 0 0 1&lt;BR /&gt;1000 2022 09 0 0 0 1&lt;BR /&gt;1000 2022 10 0 0 1 1&lt;/P&gt;&lt;P&gt;3000 2022 08 1 1 1 0&lt;BR /&gt;3000 2022 09 0 1 1 0&lt;BR /&gt;3000 2022 10 0 1 1 0&lt;BR /&gt;2000 2022 08 0 0 0 0&lt;BR /&gt;2000 2022 09 0 0 0 0&lt;BR /&gt;2000 2022 10 1 0 1 0&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;NTB(New to Business) indicator will be the main key for us, which we can identify -&lt;/P&gt;&lt;P&gt;NTB through Savings or&lt;/P&gt;&lt;P&gt;NTB through other products&lt;/P&gt;&lt;P&gt;For Customer id:1000 - NTB through loan product on Aug'22 and took savings on Oct'22 which is good to report in "took_sav_NOTthroughNTB_oct22" dataset.&amp;nbsp;&lt;/P&gt;&lt;P&gt;For Customer id:3000- NTB through savings and CA products on Aug'22 and they are still active till Oct'22 but they are not new to savings as of Oct'22, so this customer should not be reported in "took_sav_NOTthroughNTB_oct22" dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, I'm looking -&amp;nbsp; if someone took savings products in Oct'22 but they are not NTB.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope it is clear now.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kindly share your thoughts.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Jan 2023 04:15:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Historical-data/m-p/853947#M337523</guid>
      <dc:creator>AshokD</dc:creator>
      <dc:date>2023-01-16T04:15:55Z</dc:date>
    </item>
    <item>
      <title>Re: Historical data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Historical-data/m-p/853959#M337526</link>
      <description>&lt;P&gt;If I got you right then something like below could work.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  infile datalines;
  input cus year month NTB ca_ind sav_ind loan_ind;
  datum=MDY(month,15,year);
  format datum ddmmyy10.;
  datalines;
1000 2022 08 1 0 0 1
1000 2022 09 0 0 0 1
1000 2022 10 0 0 0 1
3000 2022 08 1 1 1 0
3000 2022 09 0 1 1 0
3000 2022 10 0 1 1 0
2000 2022 08 0 0 0 0
2000 2022 09 0 0 0 0
2000 2022 10 1 0 1 0
;

proc sql;
  create view v_oct22 as
    select cus, sum(ntb,sav_ind) as ntb_sav_ind_oct22, sav_ind, ntb, datum
    from test 
    where sav_ind=1 and put(datum,yymmn6.) = '202210'
  ;
  select * from v_oct22
  ;
  select 
    l.*, 
    coalesce(ntb_sav_ind_oct22,0) as ntb_sav_ind_oct22
  from 
    test l 
    left join 
    v_oct22 as r
      on l.cus=r.cus
  ;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1673857071783.png" style="width: 566px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/79420i6DADA95007EE3895/image-dimensions/566x360?v=v2" width="566" height="360" role="button" title="Patrick_0-1673857071783.png" alt="Patrick_0-1673857071783.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Jan 2023 08:18:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Historical-data/m-p/853959#M337526</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-01-16T08:18:03Z</dc:date>
    </item>
    <item>
      <title>Re: Historical data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Historical-data/m-p/853962#M337527</link>
      <description>&lt;P&gt;So you want all those which have NTB any time in the dataset, and sav_ind in the last observation?&lt;/P&gt;</description>
      <pubDate>Mon, 16 Jan 2023 09:13:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Historical-data/m-p/853962#M337527</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-01-16T09:13:10Z</dc:date>
    </item>
    <item>
      <title>Re: Historical data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Historical-data/m-p/853965#M337529</link>
      <description>&lt;P&gt;Nope, In simple note - I just want the customers who took new savings account in Oct'22. But we have two cases-&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data NTBSAV OTHSAV;&lt;/P&gt;&lt;P&gt;SET TEST;&lt;/P&gt;&lt;P&gt;??????&lt;/P&gt;&lt;P&gt;????&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;NTBSAV dataset- Customer who is NTB(New to Business - first entry historically) and took savings account in Oct'22 [Cust ID: 2000&amp;nbsp; should be reported]&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;OTHSAV dataset- Customer took savings account in Oct'22 but not NTB, since he/she already NTB through loan product. [Cust id 1000 should be reported]&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Note -&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;#1. We have to analyze historically other products and previous months entries as well.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;#2. Cust Id:3000 should not be reported in both the datasets.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sample data below:-&lt;/P&gt;&lt;P&gt;data test;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;infile datalines;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;input cus year month NTB ca_ind sav_ind loan_ind;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;1000 2022 08 1 0 0 1&lt;BR /&gt;1000 2022 09 0 0 0 1&lt;BR /&gt;1000 2022 10 0 0 1 1&lt;/P&gt;&lt;P&gt;3000 2022 08 1 1 1 0&lt;BR /&gt;3000 2022 09 0 1 1 0&lt;BR /&gt;3000 2022 10 0 1 1 0&lt;BR /&gt;2000 2022 08 0 0 0 0&lt;BR /&gt;2000 2022 09 0 0 0 0&lt;BR /&gt;2000 2022 10 1 0 1 0&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Jan 2023 10:33:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Historical-data/m-p/853965#M337529</guid>
      <dc:creator>AshokD</dc:creator>
      <dc:date>2023-01-16T10:33:14Z</dc:date>
    </item>
    <item>
      <title>Re: Historical data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Historical-data/m-p/853966#M337530</link>
      <description>&lt;P&gt;Nope, this is not working. Please look at the below sample data which I've provided. It seems like, sample data was modified in your logic. Also, please refer below for more detail about my expectations.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Once again thanks for your time.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Jan 2023 10:36:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Historical-data/m-p/853966#M337530</guid>
      <dc:creator>AshokD</dc:creator>
      <dc:date>2023-01-16T10:36:11Z</dc:date>
    </item>
    <item>
      <title>Re: Historical data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Historical-data/m-p/853986#M337537</link>
      <description>&lt;P&gt;So, when a customer is NTB and has sav_ind in October, but no previous NTB, they go into ntbsav.&lt;/P&gt;
&lt;P&gt;If there's a previous NTB without sav_ind, but sav_ind in October, they go into othsav.&lt;/P&gt;
&lt;P&gt;Those without any NTB, or no sav_ind in October, are not reported at all.&lt;/P&gt;
&lt;P&gt;Are there any observations after October 2022 in the dataset which need to be filtered out?&lt;/P&gt;</description>
      <pubDate>Mon, 16 Jan 2023 14:30:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Historical-data/m-p/853986#M337537</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-01-16T14:30:21Z</dc:date>
    </item>
    <item>
      <title>Re: Historical data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Historical-data/m-p/853989#M337538</link>
      <description>&lt;P&gt;Yeah, Exactly.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Oct'22 month will be the final data and there is no data after that.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Jan 2023 14:47:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Historical-data/m-p/853989#M337538</guid>
      <dc:creator>AshokD</dc:creator>
      <dc:date>2023-01-16T14:47:09Z</dc:date>
    </item>
    <item>
      <title>Re: Historical data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Historical-data/m-p/853997#M337542</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;
by cus year month;
run;

data
  ntbsav
  othsav
;
do until (last.cus);
  srt have;
  by cus;
  if ntb then _ntb = 1;
end;
if sav_ind
then do;
  if _ntb then output othsav;
  else if ntb then output ntbsav;
end;
drop _ntb;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 16 Jan 2023 15:48:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Historical-data/m-p/853997#M337542</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-01-16T15:48:38Z</dc:date>
    </item>
    <item>
      <title>Re: Historical data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Historical-data/m-p/854519#M337713</link>
      <description>&lt;P&gt;It is working fine now, thanks for your help.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Jan 2023 10:15:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Historical-data/m-p/854519#M337713</guid>
      <dc:creator>AshokD</dc:creator>
      <dc:date>2023-01-19T10:15:32Z</dc:date>
    </item>
  </channel>
</rss>

