<?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: Creating groups based on cumulative sum in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-groups-based-on-cumulative-sum/m-p/807798#M318534</link>
    <description>&lt;P&gt;Since here is the &lt;U&gt;SAS&lt;/U&gt; Communities and not the Excel support forum, you should supply data in SAS style, which means a data step with datalines, posted into a code box. All this is described in your welcome email (if the communities moderators told us the truth).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since your group name is dependent on the first and last member of a group, you will probably need to a double DO loop, in the first you determine the start and end of a group, in the second you reread all these values and set the new variable, and OUTPUT.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or you read through your dataset and create a CNTLIN dataset (only one pass is needed) for PROC FORMAT that formats the existing age groups into the cumulative age groups.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You might even be able to trick one of the STAT procedures into creating your groups.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What do you intend to do later on with the new group? SAS statistical procedures will honor formatted values in CLASS or similar statements, so the format is probably the way to go.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Once we have usable source data and know where you want to go with this, we can come up with code suggestions.&lt;/P&gt;</description>
    <pubDate>Thu, 14 Apr 2022 13:11:13 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2022-04-14T13:11:13Z</dc:date>
    <item>
      <title>Creating groups based on cumulative sum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-groups-based-on-cumulative-sum/m-p/807793#M318532</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was wondering if someone could help me with some coding.&lt;BR /&gt;I have a dataset that I need help grouping. The highlighted column (BR_grp) is the required column. This is created by looking at the cumulative sum for "size_total", where a new group is created once the cumulative sum has reached 2.5%.&lt;/P&gt;&lt;P&gt;I have also named the groups in "BR_grp" according to the corresponding customer age (it is preferable to have it like this however I am open to other solutions). I have tried creating a counter with multiple arrays etc and nothing seems to work.&lt;/P&gt;&lt;P&gt;I did create the variable "cum_size1" which keeps "size_total" variable if the cumulative size is less than 2.5% and 0 for anything greater... maybe that might help?&lt;BR /&gt;I've attached an excel sheet below.&lt;BR /&gt;Thank you &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&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="ResegoM_0-1649940122952.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/70384i7B4EB3E0835BE912/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ResegoM_0-1649940122952.png" alt="ResegoM_0-1649940122952.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Apr 2022 12:51:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-groups-based-on-cumulative-sum/m-p/807793#M318532</guid>
      <dc:creator>ResegoM</dc:creator>
      <dc:date>2022-04-14T12:51:19Z</dc:date>
    </item>
    <item>
      <title>Re: Creating groups based on cumulative sum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-groups-based-on-cumulative-sum/m-p/807795#M318533</link>
      <description>&lt;P&gt;Many of us will not (or cannot) download Excel files, as they are a security threat. The proper way to provide your example data is via &lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;these instructions&lt;/A&gt; (or by creating the equivalent SAS data step code by typing it in yourself). We also can't use screen captures of data to write programs.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First, I would just create consecutive group numbers rather than trying to create 18_23 in one step. It seems you should be able to do that from your cum_size1 variable. Then ... use PROC SUMMARY to find the minimum and max age in each group, and from there you can create group names like 18_23.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please explain why 43 is in a group by itself and not 43_44.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Apr 2022 13:07:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-groups-based-on-cumulative-sum/m-p/807795#M318533</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-04-14T13:07:42Z</dc:date>
    </item>
    <item>
      <title>Re: Creating groups based on cumulative sum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-groups-based-on-cumulative-sum/m-p/807798#M318534</link>
      <description>&lt;P&gt;Since here is the &lt;U&gt;SAS&lt;/U&gt; Communities and not the Excel support forum, you should supply data in SAS style, which means a data step with datalines, posted into a code box. All this is described in your welcome email (if the communities moderators told us the truth).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since your group name is dependent on the first and last member of a group, you will probably need to a double DO loop, in the first you determine the start and end of a group, in the second you reread all these values and set the new variable, and OUTPUT.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or you read through your dataset and create a CNTLIN dataset (only one pass is needed) for PROC FORMAT that formats the existing age groups into the cumulative age groups.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You might even be able to trick one of the STAT procedures into creating your groups.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What do you intend to do later on with the new group? SAS statistical procedures will honor formatted values in CLASS or similar statements, so the format is probably the way to go.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Once we have usable source data and know where you want to go with this, we can come up with code suggestions.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Apr 2022 13:11:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-groups-based-on-cumulative-sum/m-p/807798#M318534</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-04-14T13:11:13Z</dc:date>
    </item>
    <item>
      <title>Re: Creating groups based on cumulative sum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-groups-based-on-cumulative-sum/m-p/807799#M318535</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards expandtabs;
input CUST_AGE	Good	Bad	size_total :percent8.;
format size_total percent8.2;
cards;
.	859	151	4.00%
18	4	3	0.03%
19	14	7	0.08%
20	52	16	0.27%
21	107	13	0.47%
22	152	28	0.71%
23	261	51	1.23%
24	390	54	1.76%
25	379	85	1.84%
26	511	80	2.34%
27	748	108	3.39%
28	791	142	3.69%
29	828	146	3.85%
30	969	180	4.55%
31	1112	158	5.02%
32	1104	177	5.07%
33	1110	169	5.06%
34	1064	189	4.96%
35	1163	215	5.45%
36	1144	164	5.17%
37	970	157	4.46%
38	826	122	3.75%
39	716	146	3.41%
40	694	127	3.25%
41	620	90	2.81%
42	599	64	2.62%
43	542	81	2.46%
44	426	70	1.96%
45	415	75	1.94%
46	343	73	1.65%
47	353	51	1.60%
48	371	42	1.63%
49	351	32	1.52%
50	244	27	1.07%
51	208	34	0.96%
52	200	31	0.91%
53	184	20	0.81%
54	176	10	0.74%
55	141	14	0.61%
56	137	17	0.61%
57	121	13	0.53%
58	78	11	0.35%
59	60	6	0.26%
60	49	20	0.27%
61	24	3	0.11%
62	15	8	0.09%
63	28	3	0.12%
64	13	0	0.05%
65	14	0	0.06%
66	28	1	0.11%
67	12	0	0.05%
68	11	0	0.04%
69	16	5	0.08%
70	5	1	0.02%
71	10	0	0.04%
72	12	3	0.06%
73	1	0	0.00%
74	2	0	0.01%
75	2	0	0.01%
76	.	1	.
77	3	0	0.01%
79	3	0	0.01%
80	1	1	0.01%
;

data temp;
 set have;
if missing(CUST_AGE) then delete;
if cum&amp;gt;0.025 then do;group+1;cum=0;end;
cum+size_total;
run;

proc sql;
select *,min(CUST_AGE) as min,max(CUST_AGE) as max
 from temp
  group by group
order by 1;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Apr 2022 13:14:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-groups-based-on-cumulative-sum/m-p/807799#M318535</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-04-14T13:14:00Z</dc:date>
    </item>
    <item>
      <title>Re: Creating groups based on cumulative sum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-groups-based-on-cumulative-sum/m-p/807801#M318536</link>
      <description>&lt;P&gt;From what I see, 43 satisfies the &amp;gt; 2.5% rule on its own, but 44 does not. So from 44 on, it should be&lt;/P&gt;
&lt;P&gt;44-45&lt;/P&gt;
&lt;P&gt;46-47&lt;/P&gt;
&lt;P&gt;48-49&lt;/P&gt;
&lt;P&gt;50-52&lt;/P&gt;
&lt;P&gt;53-??&lt;/P&gt;</description>
      <pubDate>Thu, 14 Apr 2022 13:15:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-groups-based-on-cumulative-sum/m-p/807801#M318536</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-04-14T13:15:04Z</dc:date>
    </item>
    <item>
      <title>Re: Creating groups based on cumulative sum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-groups-based-on-cumulative-sum/m-p/807802#M318537</link>
      <description>&lt;P&gt;I'm not following your logic&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;43 is 2.46% so it is not &amp;gt;2.5%&lt;/P&gt;</description>
      <pubDate>Thu, 14 Apr 2022 13:16:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-groups-based-on-cumulative-sum/m-p/807802#M318537</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-04-14T13:16:02Z</dc:date>
    </item>
    <item>
      <title>Re: Creating groups based on cumulative sum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-groups-based-on-cumulative-sum/m-p/807804#M318538</link>
      <description>&lt;P&gt;Oh, you're right. Damn those small digits in the picture, I read 2.64. (maybe I also get old-age dyslexia)&lt;/P&gt;</description>
      <pubDate>Thu, 14 Apr 2022 13:20:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-groups-based-on-cumulative-sum/m-p/807804#M318538</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-04-14T13:20:03Z</dc:date>
    </item>
    <item>
      <title>Re: Creating groups based on cumulative sum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-groups-based-on-cumulative-sum/m-p/807823#M318543</link>
      <description>Hi ,&lt;BR /&gt;I am a little new here so I will definitely type out code for my data step the next time I may have a query.&lt;BR /&gt;For now I did see a solution below that worked.&lt;BR /&gt;Thank you for taking the time to help &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Thu, 14 Apr 2022 14:05:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-groups-based-on-cumulative-sum/m-p/807823#M318543</guid>
      <dc:creator>ResegoM</dc:creator>
      <dc:date>2022-04-14T14:05:14Z</dc:date>
    </item>
    <item>
      <title>Re: Creating groups based on cumulative sum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-groups-based-on-cumulative-sum/m-p/807824#M318544</link>
      <description>Thank you,&lt;BR /&gt;I typed this out and it worked perfectly &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Thu, 14 Apr 2022 14:05:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-groups-based-on-cumulative-sum/m-p/807824#M318544</guid>
      <dc:creator>ResegoM</dc:creator>
      <dc:date>2022-04-14T14:05:56Z</dc:date>
    </item>
  </channel>
</rss>

