<?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 Rollup data - conditional grouping in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Rollup-data-conditional-grouping/m-p/258042#M49628</link>
    <description>&lt;P&gt;I am trying to derive a new column (Column B) based on an existing column (Column A) on my data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ColumnA CountofA&amp;nbsp;&lt;/P&gt;
&lt;P&gt;12345 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 15 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;12346 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 20 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;12347 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 6 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;12348 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 20 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;12349 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;4 &amp;nbsp;&lt;/P&gt;
&lt;P&gt;12350 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;20&lt;/P&gt;
&lt;P&gt;21100 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;6&lt;/P&gt;
&lt;P&gt;21111 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 6&lt;/P&gt;
&lt;P&gt;21112 &amp;nbsp; &amp;nbsp; &amp;nbsp; 4&lt;/P&gt;
&lt;P&gt;21299 &amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;21399 &amp;nbsp; &amp;nbsp; &amp;nbsp;2&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;Desired Output &amp;nbsp;&lt;/P&gt;
&lt;P&gt;ColumnA ColumnB&lt;/P&gt;
&lt;P&gt;12345 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;12345 &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;12346 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;12346-12347 (This will get merged since the first four letter are the same)&amp;nbsp;&lt;/P&gt;
&lt;P&gt;12347 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;SPAN&gt;12346-12347 (This will get merged since the first four letter are the same)&amp;nbsp;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;12348 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;12348-12349 &lt;SPAN&gt;(This will get merged since the first four letter are the same)&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;12349 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;SPAN&gt;12348-12349 &lt;/SPAN&gt;&lt;SPAN&gt;(This will get merged since the first four letter are the same)&amp;nbsp;&lt;/SPAN&gt; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;12350 &amp;nbsp; &amp;nbsp; &amp;nbsp; 12350&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;21101 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;21101-21111 (This will get merged since the first 3 digits&amp;nbsp;are the same and their sum total is 12)&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;21111 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;SPAN&gt;21101-21111 (This will get merged since the first 3 &lt;/SPAN&gt;&lt;SPAN&gt;digits&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;are the same and their sum total is 12)&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;21112 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;21112-21399 (This will get merged since the first 2 digits are the same and their sum tota is &lt;span class="lia-unicode-emoji" title=":smiling_face_with_sunglasses:"&gt;😎&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;21299 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;SPAN&gt;21112-21399 (This will get merged since the first 2 digits are the same and their sum tota is &lt;span class="lia-unicode-emoji" title=":smiling_face_with_sunglasses:"&gt;😎&lt;/span&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;21399 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;SPAN&gt;21112-21399 (This will get merged since the first 2 digits are the same and their sum tota is &lt;span class="lia-unicode-emoji" title=":smiling_face_with_sunglasses:"&gt;😎&lt;/span&gt;&lt;/SPAN&gt;&lt;/SPAN&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;The code that I currently involves lot of manual check and so I thought of posting my question over here to get guidance&amp;nbsp;on&amp;nbsp;solving&amp;nbsp;above scenarios.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance&lt;/P&gt;</description>
    <pubDate>Mon, 21 Mar 2016 19:27:31 GMT</pubDate>
    <dc:creator>Pritish</dc:creator>
    <dc:date>2016-03-21T19:27:31Z</dc:date>
    <item>
      <title>Rollup data - conditional grouping</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rollup-data-conditional-grouping/m-p/258042#M49628</link>
      <description>&lt;P&gt;I am trying to derive a new column (Column B) based on an existing column (Column A) on my data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ColumnA CountofA&amp;nbsp;&lt;/P&gt;
&lt;P&gt;12345 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 15 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;12346 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 20 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;12347 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 6 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;12348 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 20 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;12349 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;4 &amp;nbsp;&lt;/P&gt;
&lt;P&gt;12350 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;20&lt;/P&gt;
&lt;P&gt;21100 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;6&lt;/P&gt;
&lt;P&gt;21111 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 6&lt;/P&gt;
&lt;P&gt;21112 &amp;nbsp; &amp;nbsp; &amp;nbsp; 4&lt;/P&gt;
&lt;P&gt;21299 &amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;21399 &amp;nbsp; &amp;nbsp; &amp;nbsp;2&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;Desired Output &amp;nbsp;&lt;/P&gt;
&lt;P&gt;ColumnA ColumnB&lt;/P&gt;
&lt;P&gt;12345 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;12345 &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;12346 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;12346-12347 (This will get merged since the first four letter are the same)&amp;nbsp;&lt;/P&gt;
&lt;P&gt;12347 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;SPAN&gt;12346-12347 (This will get merged since the first four letter are the same)&amp;nbsp;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;12348 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;12348-12349 &lt;SPAN&gt;(This will get merged since the first four letter are the same)&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;12349 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;SPAN&gt;12348-12349 &lt;/SPAN&gt;&lt;SPAN&gt;(This will get merged since the first four letter are the same)&amp;nbsp;&lt;/SPAN&gt; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;12350 &amp;nbsp; &amp;nbsp; &amp;nbsp; 12350&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;21101 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;21101-21111 (This will get merged since the first 3 digits&amp;nbsp;are the same and their sum total is 12)&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;21111 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;SPAN&gt;21101-21111 (This will get merged since the first 3 &lt;/SPAN&gt;&lt;SPAN&gt;digits&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;are the same and their sum total is 12)&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;21112 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;21112-21399 (This will get merged since the first 2 digits are the same and their sum tota is &lt;span class="lia-unicode-emoji" title=":smiling_face_with_sunglasses:"&gt;😎&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;21299 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;SPAN&gt;21112-21399 (This will get merged since the first 2 digits are the same and their sum tota is &lt;span class="lia-unicode-emoji" title=":smiling_face_with_sunglasses:"&gt;😎&lt;/span&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;21399 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;SPAN&gt;21112-21399 (This will get merged since the first 2 digits are the same and their sum tota is &lt;span class="lia-unicode-emoji" title=":smiling_face_with_sunglasses:"&gt;😎&lt;/span&gt;&lt;/SPAN&gt;&lt;/SPAN&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;The code that I currently involves lot of manual check and so I thought of posting my question over here to get guidance&amp;nbsp;on&amp;nbsp;solving&amp;nbsp;above scenarios.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance&lt;/P&gt;</description>
      <pubDate>Mon, 21 Mar 2016 19:27:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rollup-data-conditional-grouping/m-p/258042#M49628</guid>
      <dc:creator>Pritish</dc:creator>
      <dc:date>2016-03-21T19:27:31Z</dc:date>
    </item>
    <item>
      <title>Re: Rollup data - conditional grouping</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rollup-data-conditional-grouping/m-p/258106#M49656</link>
      <description>&lt;P&gt;Even with your notes, I have no clue of what the business rule is.&lt;/P&gt;
&lt;P&gt;Perhaps you could describe in text your real life scenario, that might help.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Mar 2016 22:45:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rollup-data-conditional-grouping/m-p/258106#M49656</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2016-03-21T22:45:30Z</dc:date>
    </item>
    <item>
      <title>Re: Rollup data - conditional grouping</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rollup-data-conditional-grouping/m-p/258124#M49666</link>
      <description>&lt;P&gt;I don't know what you are talking about .&lt;/P&gt;
&lt;P&gt;This could give you a start.&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;data have;
input ColumnA $  CountofA ;
cards;
12345         15         
12346         20         
12347         6           
12348         20         
12349        4  
12350        20
21100        6
21111         6
21112       4
21299      2
21399      2
;
run;
proc sql;
create table want as
 select a.*,b.ColumnA as b_ColumnA ,abs(compare(a.ColumnA ,b.ColumnA )) as distance
  from have as a,have as b
   where a.ColumnA ne b.ColumnA 
    group by a.ColumnA
     having calculated distance=max(calculated distance)
      order by a.ColumnA,b.ColumnA  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 22 Mar 2016 03:18:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rollup-data-conditional-grouping/m-p/258124#M49666</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-03-22T03:18:32Z</dc:date>
    </item>
    <item>
      <title>Re: Rollup data - conditional grouping</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rollup-data-conditional-grouping/m-p/258125#M49667</link>
      <description>&lt;P&gt;Sorry for the poor description.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's what I am trying to achieve:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Basically, I have a table which contains unique 5 digit number and total record counts associated with it. Now the 5 digit numbers are not in sequence, however they could have either the first four digits or first three or first two digits in &amp;nbsp;common. (&lt;STRONG&gt;0152&lt;/STRONG&gt;1, &lt;STRONG&gt;0152&lt;/STRONG&gt;9). Now using this numbers, I want to roll up the date based on each number. So let's say if number 01521 have more than 10 records, however 01529 doesn't have 10 records, I would like to create a new column which will tell me which numbers where grouped together (for ex: 01521-01529). Here's are some sample records:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Column A &amp;nbsp;# of Records&lt;/P&gt;
&lt;P&gt;01111 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 111&amp;nbsp;&lt;/P&gt;
&lt;P&gt;01119 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;6&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now since the first four digits are common for above numbers, I would like to create a new column with value for each row as '01111-01119'.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Similarly, here is the second scenario where I have exhaused the first four combinations. So I would go for matching the first three digits :&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Column A # of Records&lt;/P&gt;
&lt;P&gt;01255 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;99&lt;/P&gt;
&lt;P&gt;01299 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 6&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Again I only need to do a grouping if the number of records are less than 10.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the code that I have which definitely not the best piece of code:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;BR /&gt;merge test1&lt;BR /&gt; test1 (firstobs=2 rename=(columna=_columna1 count=_count1 flag=_flag1 ))&lt;BR /&gt; test1 (firstobs=3 rename=(columna=_columna2 count=_count2 flag=_flag2 ))&lt;BR /&gt;;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;if count (# of records)&amp;nbsp;&amp;lt; 10 then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if substr(columna,1,4) = substr(_columna1,1,4) then do;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt; if count + _count1 &amp;gt;= 10 then derived_column&amp;nbsp;= strip(column) || '-' || strip(_columna1);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;else if substr(column,1,4) = substr(_columna2,1,4) then do; &lt;BR /&gt; if count + _count1 + _count2 &amp;gt;= 10 then do; &lt;BR /&gt;derived_column&amp;nbsp;= strip(column) || '-' || strip(_columna2);&lt;BR /&gt; end;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The problem with above program is I am not able to derive the new column for records that have value of &amp;gt; 10.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;HTH. Thanks!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Mar 2016 03:43:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rollup-data-conditional-grouping/m-p/258125#M49667</guid>
      <dc:creator>Pritish</dc:creator>
      <dc:date>2016-03-22T03:43:42Z</dc:date>
    </item>
  </channel>
</rss>

