<?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: Counts Number of Active Customers in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Counts-Number-of-Active-Customers/m-p/926974#M364822</link>
    <description>&lt;P&gt;Going forward please provide data as text and not as screenshot. What's the most appreciated is if you provide sample data via a tested SAS script that creates the data similar to below data have step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One way to go:&lt;/P&gt;
&lt;P&gt;Create a table with one row per customer and year which then is very easy to use with Proc Report or Proc Tabulate.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input customer$ start_date:ddmmyy10. end_date:ddmmyy10.;
  format start_date end_date ddmmyy10.;
  datalines;
A 01/01/2004 31/12/2004
B 01/01/2005 31/12/2009
C 01/01/2004 31/12/9999
;

%let stop_year=%sysfunc(year(%sysfunc(today())));
data prep;
  set have;
  do i=0 to intck('year',start_date,end_date);
    year=year(intnx('year',start_date,i));
    if year&amp;gt;&amp;amp;stop_year then leave;
    year2=year;
    output;
  end;
  keep customer year year2;
run;

proc tabulate data=prep;
  class year year2;
  keylabel n=' ';
  table year, year2;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 04 May 2024 02:48:50 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2024-05-04T02:48:50Z</dc:date>
    <item>
      <title>Counts Number of Active Customers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counts-Number-of-Active-Customers/m-p/926960#M364815</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've a sample input data below and the expected output format.&lt;/P&gt;
&lt;P&gt;I need to find number of active customers as per the start date of the year and their based on end date, I've to keep the count added for each year.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example,&lt;/P&gt;
&lt;P&gt;Customer A,H,I - Active from 2004, so we have 3 customers active from 2004 and I'm keeping the count added horizontally for each year and by 2009 one customer got dropped. So for 2010 - customer count was 2.&lt;/P&gt;
&lt;P&gt;Similarly I've to populate the same for the next row active from&amp;nbsp; 2005 and followed by&amp;nbsp; other rows.&lt;/P&gt;
&lt;P&gt;Could you please suggest me the best approach to get this done ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance for your help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="input data.PNG" style="width: 237px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/96159iD064DC66864F27CA/image-size/large?v=v2&amp;amp;px=999" role="button" title="input data.PNG" alt="input data.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;&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Output data.PNG" style="width: 520px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/96161iE30E63CDB3C04A6B/image-size/large?v=v2&amp;amp;px=999" role="button" title="Output data.PNG" alt="Output data.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 04 May 2024 00:35:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counts-Number-of-Active-Customers/m-p/926960#M364815</guid>
      <dc:creator>AshokD</dc:creator>
      <dc:date>2024-05-04T00:35:07Z</dc:date>
    </item>
    <item>
      <title>Re: Counts Number of Active Customers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counts-Number-of-Active-Customers/m-p/926974#M364822</link>
      <description>&lt;P&gt;Going forward please provide data as text and not as screenshot. What's the most appreciated is if you provide sample data via a tested SAS script that creates the data similar to below data have step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One way to go:&lt;/P&gt;
&lt;P&gt;Create a table with one row per customer and year which then is very easy to use with Proc Report or Proc Tabulate.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input customer$ start_date:ddmmyy10. end_date:ddmmyy10.;
  format start_date end_date ddmmyy10.;
  datalines;
A 01/01/2004 31/12/2004
B 01/01/2005 31/12/2009
C 01/01/2004 31/12/9999
;

%let stop_year=%sysfunc(year(%sysfunc(today())));
data prep;
  set have;
  do i=0 to intck('year',start_date,end_date);
    year=year(intnx('year',start_date,i));
    if year&amp;gt;&amp;amp;stop_year then leave;
    year2=year;
    output;
  end;
  keep customer year year2;
run;

proc tabulate data=prep;
  class year year2;
  keylabel n=' ';
  table year, year2;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 04 May 2024 02:48:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counts-Number-of-Active-Customers/m-p/926974#M364822</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-05-04T02:48:50Z</dc:date>
    </item>
    <item>
      <title>Re: Counts Number of Active Customers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counts-Number-of-Active-Customers/m-p/926985#M364829</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for sharing the script.&lt;/P&gt;
&lt;P&gt;I've tried with the below sample data&amp;nbsp; but it looks not as expected. For example, customers who has start date with 2004 and they should be tracked within first row but the below output shows diagonally and also it is getting added in the next row along with 2005 and other years.&lt;/P&gt;
&lt;P&gt;I've posted the expected output vs actual output.&amp;nbsp;Could you please have a look and share your thoughts.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have;&lt;BR /&gt;input customer$ start_date:ddmmyy10. end_date:ddmmyy10.;&lt;BR /&gt;format start_date end_date ddmmyy10.;&lt;BR /&gt;datalines;&lt;BR /&gt;A 01/01/2004 31/12/9999&lt;BR /&gt;B 01/01/2005 01/01/2009&lt;BR /&gt;C 01/01/2005 31/12/9999&lt;BR /&gt;D 01/01/2006 01/01/2009&lt;BR /&gt;E 01/01/2006 31/12/9999&lt;BR /&gt;F 01/01/2007 01/01/2008&lt;BR /&gt;G 01/01/2007 31/12/9999&lt;BR /&gt;H 01/01/2004 01/01/2009&lt;BR /&gt;I 01/01/2004 31/12/9999&lt;BR /&gt;J 01/01/2008 01/01/2010&lt;BR /&gt;K 01/01/2008 31/12/9999&lt;BR /&gt;;&lt;/P&gt;
&lt;P&gt;%let stop_year=%sysfunc(year(%sysfunc(today())));&lt;BR /&gt;data prep;&lt;BR /&gt;set have;&lt;BR /&gt;do i=0 to intck('year',start_date,end_date);&lt;BR /&gt;year=year(intnx('year',start_date,i));&lt;BR /&gt;if year&amp;gt;&amp;amp;stop_year then leave;&lt;BR /&gt;year2=year;&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;keep customer year year2;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;proc tabulate data=prep;&lt;BR /&gt;class year year2;&lt;BR /&gt;keylabel n=' ';&lt;BR /&gt;table year, year2;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Actual Output:-&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Output data1.PNG" style="width: 847px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/96168i079907728F3EE9FA/image-size/large?v=v2&amp;amp;px=999" role="button" title="Output data1.PNG" alt="Output data1.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Expected Output:-&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Output data.PNG" style="width: 520px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/96169i836AA625E8D0E36C/image-size/large?v=v2&amp;amp;px=999" role="button" title="Output data.PNG" alt="Output data.PNG" /&gt;&lt;/span&gt;&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 04 May 2024 09:26:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counts-Number-of-Active-Customers/m-p/926985#M364829</guid>
      <dc:creator>AshokD</dc:creator>
      <dc:date>2024-05-04T09:26:25Z</dc:date>
    </item>
    <item>
      <title>Re: Counts Number of Active Customers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counts-Number-of-Active-Customers/m-p/926988#M364830</link>
      <description>&lt;P&gt;As you can see in the script I've shared it's just about creating the data that's best suited for the Proc you want to use it.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't understand how you would get to the count of 2 in the highlighted cell - what it means - and though can't create the prep data step logic for it.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1714818300113.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/96170i916360562A215988/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1714818300113.png" alt="Patrick_0-1714818300113.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See if below code gives you sufficient pointers to prepare the data the way you need it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input customer$ start_date:ddmmyy10. end_date:ddmmyy10.;
  format start_date end_date ddmmyy10.;
  datalines;
A 01/01/2004 31/12/9999
B 01/01/2005 01/01/2009
C 01/01/2005 31/12/9999
D 01/01/2006 01/01/2009
E 01/01/2006 31/12/9999
F 01/01/2007 01/01/2008
G 01/01/2007 31/12/9999
H 01/01/2004 01/01/2009
I 01/01/2004 31/12/9999
J 01/01/2008 01/01/2010
K 01/01/2008 31/12/9999
;

%let stop_year=%sysfunc(year(%sysfunc(today())));
%let stop_year=%sysfunc(year(%sysfunc(inputn(31jan2010,date9.))));
data prep;
  set have;
  start_year=year(start_date);
  do i=0 to intck('year',start_date,end_date);
    active_year=year(intnx('year',start_date,i));
    if active_year&amp;gt;&amp;amp;stop_year then leave;
    output;
  end;
  keep customer start_year active_year;
run;

data layout;
  do start_year=2004 to &amp;amp;stop_year;
    do active_year=2004 to &amp;amp;stop_year;
      output;
    end;
  end;
run;

proc tabulate data=prep classdata=layout;
  class start_year active_year;
  keylabel n=' ';
  table start_year, active_year;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_1-1714818450318.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/96171iD35F59370E6B7F3F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_1-1714818450318.png" alt="Patrick_1-1714818450318.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 04 May 2024 10:27:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counts-Number-of-Active-Customers/m-p/926988#M364830</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-05-04T10:27:35Z</dc:date>
    </item>
    <item>
      <title>Re: Counts Number of Active Customers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counts-Number-of-Active-Customers/m-p/927009#M364842</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Apologies, You're right.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've updated the above highlighted cell wrongly. Now the data looks good and the logic works.&lt;/P&gt;
&lt;P&gt;Thank you so much for your help.&lt;/P&gt;</description>
      <pubDate>Sat, 04 May 2024 13:10:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counts-Number-of-Active-Customers/m-p/927009#M364842</guid>
      <dc:creator>AshokD</dc:creator>
      <dc:date>2024-05-04T13:10:27Z</dc:date>
    </item>
  </channel>
</rss>

