<?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: Summarizing data-membership numbers etc in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Summarizing-data-membership-numbers-etc/m-p/321119#M70824</link>
    <description>&lt;P&gt;Merry Christmas&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's a solution that tested. It's based on the idea of transposing your data to a more workable format first - a long format, and adding indicator variables for first and last years. You don't mention how the lastYear is identified, as I assume it has to be more than the last record. &amp;nbsp;I'll leave that logic up to you.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*Read in sample data;

data WORK.TEST;
	infile datalines dsd truncover;
	input Person_ID_Unencrypted:$9. Gender:$8. Date_of_Birth:$10. County:$14. 
		Claims_Paid_2011:32. Payment_Amount_Prof___Fac_2011:DOLLAR21.2 
		Claims_Paid_2012:32. Payment_Amount_Prof___Fac_2012:DOLLAR21.2 
		Claims_Paid_2013:32. Payment_Amount_Prof___Fac_2013:DOLLAR21.2 
		Claims_Paid_2014:32. Payment_Amount_Prof___Fac_2014:DOLLAR21.2 
		Claims_Paid_2015:32. Payment_Amount_Prof___Fac_2015:DOLLAR21.2 
		Claims_Paid_2016:32. Payment_Amount_Prof___Fac_2016:DOLLAR21.2;
	datalines4;
94604050A,Female,06/25/1973,Androscoggin,,,,,,,,,6,"$4,247.89",23,"$7,327.37"
94603100A,Male,06/20/1961,Cumberland,6,$67.47,7,$65.24,16,$311.07,13,"$2,795.79",17,$201.22,,
94602853A,Male,06/24/1949,Oxford,,,,,,,16,"$65,874.18",26,"$3,625.06",30,"$2,946.30"
94602600A,Male,11/19/1960,Kennebec,13,$777.11,51,"$8,004.18",29,"$39,693.57",25,"$8,292.15",50,"$13,131.50",29,"$22,569.97"
94602570A,Male,01/18/1960,Penobscot,18,"$1,355.37",25,"$2,313.65",19,"$2,472.84",41,"$16,849.72",21,"$5,170.58",17,"$1,885.47"
94601310A,Male,01/05/1960,Cumberland,,,8,$993.41,7,$842.01,12,"$1,226.75",2,$22.30,,
94599480A,Male,09/30/1958,Cumberland,,,4,$471.54,7,$1.23,3,$29.75,16,$288.53,27,"$2,411.29"
94598333A,Male,12/13/1972,Cumberland,,,,,,,1,$83.80,,,,
94597070A,Female,04/04/1959,Piscataquis,8,"$2,027.79",11,"$3,132.89",11,$688.19,25,"$2,672.37",14,$93.44,21,"$-1,386.13"
94596570A,Male,09/21/1959,Piscataquis,6,$657.30,10,"$1,276.86",8,$861.97,1,$-4.69,,,,
;;;;
	
	
*Transpose data to a more friendly format;
data flipped;
	set test;
	array claims(*) claims_:;
	array payment(*) payment_:;

	do i=1 to dim(claims);
		claim_paid=claims(i);
		year=input(scan(vname(claims(I)), 3, "_"), 8.);
		payments_total=payment(i);

		if payments_total ne . then
			output;
	end;
	drop claims_: payment_: i;
run;

*Sort data for BY group processing;

proc sort data=flipped;
	by person_id_Unencrypted;
run;

*Identify first and last year per customer;

data flipped2;
	set flipped;
	by person_id_unencrypted;
	firstYear=first.person_id_unencrypted;
	lastYear=last.person_id_unencrypted;
run;

/*Summary steps*/
proc means data=flipped2 sum noprint nway;
	class year;
	output out=summary_by_year (drop=_type_ _freq_) n(claim_paid)=num_members 
		sum(claim_paid)=total_num_claims sum(payments_total)=total_payments 
		sum(firstYear)=newMembers sum(lastYear)=leavingMembers;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 26 Dec 2016 01:34:00 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2016-12-26T01:34:00Z</dc:date>
    <item>
      <title>Summarizing data-membership numbers etc</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summarizing-data-membership-numbers-etc/m-p/321101#M70813</link>
      <description>&lt;P&gt;Merry Xmas to all you talented people! I have the data in following format below-&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm looking to extract following information-&lt;/P&gt;
&lt;P&gt;1. Number of members each year who have claims, number of those claims and claim amounts (I solved this part by using simple sas code, but had to do for each year seperately and then merge all six datasets-im sure there is more efficient way to do it)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. Member progression each year- new distinct members each year who enter and exit the system- many members have claims in multiple years, but i want to find out how many new members enter the system each year or exit the system permanently, list of those members by gender, county type etc. The tricky part here is that member could have claim in 2011 and then again in 2014 and 2016, so those members should not be counted as new members, but still be identified.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="2631"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="167"&gt;Person ID Unencrypted&lt;/TD&gt;
&lt;TD width="61"&gt;Gender&lt;/TD&gt;
&lt;TD width="96"&gt;Date of Birth&lt;/TD&gt;
&lt;TD width="87"&gt;County&lt;/TD&gt;
&lt;TD width="70"&gt;Claims Paid_2011&lt;/TD&gt;
&lt;TD width="300"&gt;Payment Amount Prof &amp;amp; Fac_2011&lt;/TD&gt;
&lt;TD width="70"&gt;Claims Paid_2012&lt;/TD&gt;
&lt;TD width="300"&gt;Payment Amount Prof &amp;amp; Fac_2012&lt;/TD&gt;
&lt;TD width="70"&gt;Claims Paid_2013&lt;/TD&gt;
&lt;TD width="300"&gt;Payment Amount Prof &amp;amp; Fac_2013&lt;/TD&gt;
&lt;TD width="70"&gt;Claims Paid_2014&lt;/TD&gt;
&lt;TD width="300"&gt;Payment Amount Prof &amp;amp; Fac_2014&lt;/TD&gt;
&lt;TD width="70"&gt;Claims Paid_2015&lt;/TD&gt;
&lt;TD width="300"&gt;Payment Amount Prof &amp;amp; Fac_2015&lt;/TD&gt;
&lt;TD width="70"&gt;Claims Paid_2016&lt;/TD&gt;
&lt;TD width="300"&gt;Payment Amount Prof &amp;amp; Fac_2016&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;0001&lt;/TD&gt;
&lt;TD&gt;Female&lt;/TD&gt;
&lt;TD&gt;09/13/1991&lt;/TD&gt;
&lt;TD&gt;Aroostook&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;$57.50&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;0002&lt;/TD&gt;
&lt;TD&gt;Female&lt;/TD&gt;
&lt;TD&gt;10/12/1959&lt;/TD&gt;
&lt;TD&gt;Aroostook&lt;/TD&gt;
&lt;TD&gt;6&lt;/TD&gt;
&lt;TD&gt;$141.31&lt;/TD&gt;
&lt;TD&gt;17&lt;/TD&gt;
&lt;TD&gt;$169.56&lt;/TD&gt;
&lt;TD&gt;18&lt;/TD&gt;
&lt;TD&gt;$632.27&lt;/TD&gt;
&lt;TD&gt;11&lt;/TD&gt;
&lt;TD&gt;$355.29&lt;/TD&gt;
&lt;TD&gt;10&lt;/TD&gt;
&lt;TD&gt;$367.13&lt;/TD&gt;
&lt;TD&gt;6&lt;/TD&gt;
&lt;TD&gt;$298.35&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;0003&lt;/TD&gt;
&lt;TD&gt;Female&lt;/TD&gt;
&lt;TD&gt;05/22/1960&lt;/TD&gt;
&lt;TD&gt;Aroostook&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;3&lt;/TD&gt;
&lt;TD&gt;$0.00&lt;/TD&gt;
&lt;TD&gt;7&lt;/TD&gt;
&lt;TD&gt;$92.40&lt;/TD&gt;
&lt;TD&gt;3&lt;/TD&gt;
&lt;TD&gt;$28.57&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;0004&lt;/TD&gt;
&lt;TD&gt;Male&lt;/TD&gt;
&lt;TD&gt;12/07/1965&lt;/TD&gt;
&lt;TD&gt;Aroostook&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;$71.52&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;0005&lt;/TD&gt;
&lt;TD&gt;Male&lt;/TD&gt;
&lt;TD&gt;10/23/1964&lt;/TD&gt;
&lt;TD&gt;Somerset&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;6&lt;/TD&gt;
&lt;TD&gt;$689.52&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;0006&lt;/TD&gt;
&lt;TD&gt;Male&lt;/TD&gt;
&lt;TD&gt;05/04/1942&lt;/TD&gt;
&lt;TD&gt;Cumberland&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;$48.44&lt;/TD&gt;
&lt;TD&gt;5&lt;/TD&gt;
&lt;TD&gt;$44.04&lt;/TD&gt;
&lt;TD&gt;4&lt;/TD&gt;
&lt;TD&gt;$0.00&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;$71.70&lt;/TD&gt;
&lt;TD&gt;3&lt;/TD&gt;
&lt;TD&gt;$71.29&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Sun, 25 Dec 2016 21:08:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summarizing-data-membership-numbers-etc/m-p/321101#M70813</guid>
      <dc:creator>devsas</dc:creator>
      <dc:date>2016-12-25T21:08:38Z</dc:date>
    </item>
    <item>
      <title>Re: Summarizing data-membership numbers etc</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summarizing-data-membership-numbers-etc/m-p/321104#M70815</link>
      <description>&lt;P&gt;Fortunately, all your issues have a solution that uses the same idea, BY GROUP processing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can identify a BY GROUP by several different variables. For example, in your first question, your BY group would be YEAR. If you post your current code, we can suggest ways to add in the BY YEAR concept.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For you second it would be the person. You don't post what you want as output, but I would recommend Person, StartYear, EndYear.&lt;/P&gt;
&lt;P&gt;You could also do this via a PROC MEANS or SUMMARY recognizing that the smallest (MIN) year is the start and the highest (MAX) is the end year. Then you can summarize your flow over a year by using PROC FREQ on the StartYear and EndYear variables.&amp;nbsp;&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;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 25 Dec 2016 21:38:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summarizing-data-membership-numbers-etc/m-p/321104#M70815</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-12-25T21:38:30Z</dc:date>
    </item>
    <item>
      <title>Re: Summarizing data-membership numbers etc</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summarizing-data-membership-numbers-etc/m-p/321105#M70816</link>
      <description>&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/lrcon/69852/HTML/default/viewer.htm#n138da4gme3zb7n1nifpfhqv7clq.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrcon/69852/HTML/default/viewer.htm#n138da4gme3zb7n1nifpfhqv7clq.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A quick read of the Understanding BY Group section would help, and then the rest of the section.&lt;/P&gt;</description>
      <pubDate>Sun, 25 Dec 2016 21:39:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summarizing-data-membership-numbers-etc/m-p/321105#M70816</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-12-25T21:39:44Z</dc:date>
    </item>
    <item>
      <title>Re: Summarizing data-membership numbers etc</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summarizing-data-membership-numbers-etc/m-p/321107#M70817</link>
      <description>&lt;P&gt;Thanks Reeza. I used the following code to get first year numbers and then have to do it 5 more times to get other year numbers. I understand the group by processing, but im getting confused for membership numbers when they go in and out of system.&lt;/P&gt;
&lt;P&gt;Also, i see my example data is not posted fully. I remember there is a post which helps you convert sas dataset into code for demonstration purpose. I cant find that on forum. I will then post what i want for output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;create table diab2011 as select count(person_id_unencrypted) as members2011, sum(Claims_Paid_2011) as claims2011, sum(Payment_Amount_Prof___Fac_2011) as total_payment_2011 &lt;BR /&gt;from diabetes where Claims_Paid_2011 &amp;lt;&amp;gt; . and Payment_Amount_Prof___Fac_2011 &amp;lt;&amp;gt; . ;&lt;BR /&gt;quit;&lt;/P&gt;</description>
      <pubDate>Sun, 25 Dec 2016 21:44:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summarizing-data-membership-numbers-etc/m-p/321107#M70817</guid>
      <dc:creator>devsas</dc:creator>
      <dc:date>2016-12-25T21:44:54Z</dc:date>
    </item>
    <item>
      <title>Re: Summarizing data-membership numbers etc</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summarizing-data-membership-numbers-etc/m-p/321108#M70818</link>
      <description>&lt;P&gt;There are additional 10 columns in my data &amp;nbsp;from 2012 till 2016 respectively for number of claims and claim amounts for each member. Below&amp;nbsp;is what I'm looking for final output-&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Year &amp;nbsp;county gender no_of_members &amp;nbsp;no_of_New_members Members_lost no_of_claims claim_amounts&lt;/P&gt;
&lt;P&gt;2011 &amp;nbsp;A &amp;nbsp; M&lt;/P&gt;
&lt;P&gt;2011 &amp;nbsp;A &amp;nbsp; F&lt;/P&gt;
&lt;P&gt;2011 B &amp;nbsp; M&lt;/P&gt;
&lt;P&gt;2011 B &amp;nbsp; F&lt;/P&gt;
&lt;P&gt;2012 A &amp;nbsp;M&lt;/P&gt;
&lt;P&gt;2012 A F&lt;/P&gt;</description>
      <pubDate>Sun, 25 Dec 2016 22:06:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summarizing-data-membership-numbers-etc/m-p/321108#M70818</guid>
      <dc:creator>devsas</dc:creator>
      <dc:date>2016-12-25T22:06:06Z</dc:date>
    </item>
    <item>
      <title>Re: Summarizing data-membership numbers etc</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summarizing-data-membership-numbers-etc/m-p/321109#M70819</link>
      <description>&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 25 Dec 2016 22:14:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summarizing-data-membership-numbers-etc/m-p/321109#M70819</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-12-25T22:14:57Z</dc:date>
    </item>
    <item>
      <title>Re: Summarizing data-membership numbers etc</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summarizing-data-membership-numbers-etc/m-p/321114#M70822</link>
      <description>&lt;P&gt;Thanks. Here is the sample data-&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WORK.TEST;
infile datalines dsd truncover;
input Person_ID_Unencrypted:$9. Gender:$8. Date_of_Birth:$10. County:$14. Claims_Paid_2011:32. Payment_Amount_Prof___Fac_2011:DOLLAR21.2 Claims_Paid_2012:32. Payment_Amount_Prof___Fac_2012:DOLLAR21.2 Claims_Paid_2013:32. Payment_Amount_Prof___Fac_2013:DOLLAR21.2 Claims_Paid_2014:32. Payment_Amount_Prof___Fac_2014:DOLLAR21.2 Claims_Paid_2015:32. Payment_Amount_Prof___Fac_2015:DOLLAR21.2 Claims_Paid_2016:32. Payment_Amount_Prof___Fac_2016:DOLLAR21.2;
datalines4;
94604050A,Female,06/25/1973,Androscoggin,,,,,,,,,6,"$4,247.89",23,"$7,327.37"
94603100A,Male,06/20/1961,Cumberland,6,$67.47,7,$65.24,16,$311.07,13,"$2,795.79",17,$201.22,,
94602853A,Male,06/24/1949,Oxford,,,,,,,16,"$65,874.18",26,"$3,625.06",30,"$2,946.30"
94602600A,Male,11/19/1960,Kennebec,13,$777.11,51,"$8,004.18",29,"$39,693.57",25,"$8,292.15",50,"$13,131.50",29,"$22,569.97"
94602570A,Male,01/18/1960,Penobscot,18,"$1,355.37",25,"$2,313.65",19,"$2,472.84",41,"$16,849.72",21,"$5,170.58",17,"$1,885.47"
94601310A,Male,01/05/1960,Cumberland,,,8,$993.41,7,$842.01,12,"$1,226.75",2,$22.30,,
94599480A,Male,09/30/1958,Cumberland,,,4,$471.54,7,$1.23,3,$29.75,16,$288.53,27,"$2,411.29"
94598333A,Male,12/13/1972,Cumberland,,,,,,,1,$83.80,,,,
94597070A,Female,04/04/1959,Piscataquis,8,"$2,027.79",11,"$3,132.89",11,$688.19,25,"$2,672.37",14,$93.44,21,"$-1,386.13"
94596570A,Male,09/21/1959,Piscataquis,6,$657.30,10,"$1,276.86",8,$861.97,1,$-4.69,,,,
;;;;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 25 Dec 2016 23:33:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summarizing-data-membership-numbers-etc/m-p/321114#M70822</guid>
      <dc:creator>devsas</dc:creator>
      <dc:date>2016-12-25T23:33:37Z</dc:date>
    </item>
    <item>
      <title>Re: Summarizing data-membership numbers etc</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summarizing-data-membership-numbers-etc/m-p/321119#M70824</link>
      <description>&lt;P&gt;Merry Christmas&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's a solution that tested. It's based on the idea of transposing your data to a more workable format first - a long format, and adding indicator variables for first and last years. You don't mention how the lastYear is identified, as I assume it has to be more than the last record. &amp;nbsp;I'll leave that logic up to you.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*Read in sample data;

data WORK.TEST;
	infile datalines dsd truncover;
	input Person_ID_Unencrypted:$9. Gender:$8. Date_of_Birth:$10. County:$14. 
		Claims_Paid_2011:32. Payment_Amount_Prof___Fac_2011:DOLLAR21.2 
		Claims_Paid_2012:32. Payment_Amount_Prof___Fac_2012:DOLLAR21.2 
		Claims_Paid_2013:32. Payment_Amount_Prof___Fac_2013:DOLLAR21.2 
		Claims_Paid_2014:32. Payment_Amount_Prof___Fac_2014:DOLLAR21.2 
		Claims_Paid_2015:32. Payment_Amount_Prof___Fac_2015:DOLLAR21.2 
		Claims_Paid_2016:32. Payment_Amount_Prof___Fac_2016:DOLLAR21.2;
	datalines4;
94604050A,Female,06/25/1973,Androscoggin,,,,,,,,,6,"$4,247.89",23,"$7,327.37"
94603100A,Male,06/20/1961,Cumberland,6,$67.47,7,$65.24,16,$311.07,13,"$2,795.79",17,$201.22,,
94602853A,Male,06/24/1949,Oxford,,,,,,,16,"$65,874.18",26,"$3,625.06",30,"$2,946.30"
94602600A,Male,11/19/1960,Kennebec,13,$777.11,51,"$8,004.18",29,"$39,693.57",25,"$8,292.15",50,"$13,131.50",29,"$22,569.97"
94602570A,Male,01/18/1960,Penobscot,18,"$1,355.37",25,"$2,313.65",19,"$2,472.84",41,"$16,849.72",21,"$5,170.58",17,"$1,885.47"
94601310A,Male,01/05/1960,Cumberland,,,8,$993.41,7,$842.01,12,"$1,226.75",2,$22.30,,
94599480A,Male,09/30/1958,Cumberland,,,4,$471.54,7,$1.23,3,$29.75,16,$288.53,27,"$2,411.29"
94598333A,Male,12/13/1972,Cumberland,,,,,,,1,$83.80,,,,
94597070A,Female,04/04/1959,Piscataquis,8,"$2,027.79",11,"$3,132.89",11,$688.19,25,"$2,672.37",14,$93.44,21,"$-1,386.13"
94596570A,Male,09/21/1959,Piscataquis,6,$657.30,10,"$1,276.86",8,$861.97,1,$-4.69,,,,
;;;;
	
	
*Transpose data to a more friendly format;
data flipped;
	set test;
	array claims(*) claims_:;
	array payment(*) payment_:;

	do i=1 to dim(claims);
		claim_paid=claims(i);
		year=input(scan(vname(claims(I)), 3, "_"), 8.);
		payments_total=payment(i);

		if payments_total ne . then
			output;
	end;
	drop claims_: payment_: i;
run;

*Sort data for BY group processing;

proc sort data=flipped;
	by person_id_Unencrypted;
run;

*Identify first and last year per customer;

data flipped2;
	set flipped;
	by person_id_unencrypted;
	firstYear=first.person_id_unencrypted;
	lastYear=last.person_id_unencrypted;
run;

/*Summary steps*/
proc means data=flipped2 sum noprint nway;
	class year;
	output out=summary_by_year (drop=_type_ _freq_) n(claim_paid)=num_members 
		sum(claim_paid)=total_num_claims sum(payments_total)=total_payments 
		sum(firstYear)=newMembers sum(lastYear)=leavingMembers;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Dec 2016 01:34:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summarizing-data-membership-numbers-etc/m-p/321119#M70824</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-12-26T01:34:00Z</dc:date>
    </item>
    <item>
      <title>Re: Summarizing data-membership numbers etc</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summarizing-data-membership-numbers-etc/m-p/321134#M70828</link>
      <description>&lt;P&gt;Thanks Reeza. I'm out now, but will run the code soon. Last year is basically the year after which they have no claims. &amp;nbsp;So, a person could have claim in 2013 and then again in 2016, the last year will be 2016. If only in 2012 and 2013, then 2013 is last year.&lt;/P&gt;</description>
      <pubDate>Mon, 26 Dec 2016 04:28:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summarizing-data-membership-numbers-etc/m-p/321134#M70828</guid>
      <dc:creator>devsas</dc:creator>
      <dc:date>2016-12-26T04:28:29Z</dc:date>
    </item>
    <item>
      <title>Re: Summarizing data-membership numbers etc</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summarizing-data-membership-numbers-etc/m-p/322252#M71283</link>
      <description>&lt;P&gt;Reeza, the code above has worked very well. I just realized that there are some cases where a member can have multiple records in the same year as they change counties. Now this doesnt change any other calculations in your code, except the number of members each year. Because in cases where there are multiple claims for same year, those members are counted twice using this below in your code.&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token function"&gt;n&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;claim_paid&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;num_members &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;I tried to solve this problem by flagging such cases in flipped2 dataset so that I can subtract these cases later on. I used the following code, but its not giving me the desired result. instead it is flagging those cases where members have only one record.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data flagged;&lt;BR /&gt;set flipped2;&lt;BR /&gt;by person_id_unencrypted year;&lt;BR /&gt;if first.person_id_unencrypted then do;&lt;BR /&gt;if year = lag(year) then flag =1 ;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sorry for troubling you again. Thanks so much as always!&lt;/P&gt;</description>
      <pubDate>Tue, 03 Jan 2017 21:28:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summarizing-data-membership-numbers-etc/m-p/322252#M71283</guid>
      <dc:creator>devsas</dc:creator>
      <dc:date>2017-01-03T21:28:42Z</dc:date>
    </item>
    <item>
      <title>Re: Summarizing data-membership numbers etc</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summarizing-data-membership-numbers-etc/m-p/322255#M71285</link>
      <description>&lt;P&gt;Your on the right track. If you're using BY group processing and see this type of code, know that you're on the wrong track&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if year=lag(year)&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This means you need to add year to your BY statement.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The idea here, is flag the first occurence for each ID, and add a record that is 1 for the first and then 0 otherwise for each person/year. Then for the number of users, add up the variable.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are three changes below, with comments Change#&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*Sort data for BY group processing;

proc sort data=flipped;
	by person_id_Unencrypted year; /*Change1 - add year to sort/BY*/
run;

*Identify first and last year per customer;

data flipped2;
	set flipped;
	by person_id_unencrypted year; /*Change1 - add year to sort/BY*/
	firstYear=first.person_id_unencrypted;
	lastYear=last.person_id_unencrypted;
    if first.year then person_count=1; else person_count=0; /* Change2 - Add flag for first record per person per year*/
run;

/*Summary steps*/
proc means data=flipped2 sum noprint nway;
	class year;
	output out=summary_by_year (drop=_type_ _freq_) sum(person_count)=num_members /*Change3 - Sum the new variable created as number of members*/ 
		sum(claim_paid)=total_num_claims sum(payments_total)=total_payments 
		sum(firstYear)=newMembers sum(lastYear)=leavingMembers;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Jan 2017 21:43:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summarizing-data-membership-numbers-etc/m-p/322255#M71285</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-01-03T21:43:15Z</dc:date>
    </item>
    <item>
      <title>Re: Summarizing data-membership numbers etc</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summarizing-data-membership-numbers-etc/m-p/322316#M71297</link>
      <description>&lt;P&gt;Thanks a lot, Reeza!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Jan 2017 03:37:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summarizing-data-membership-numbers-etc/m-p/322316#M71297</guid>
      <dc:creator>devsas</dc:creator>
      <dc:date>2017-01-04T03:37:57Z</dc:date>
    </item>
  </channel>
</rss>

