<?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: Using two columns to group another table in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-two-columns-to-group-another-table/m-p/589310#M168536</link>
    <description>&lt;P&gt;Makes sense. Anytime. Glad you found your answer &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 17 Sep 2019 11:29:01 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2019-09-17T11:29:01Z</dc:date>
    <item>
      <title>Using two columns to group another table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-two-columns-to-group-another-table/m-p/589302#M168529</link>
      <description>&lt;P&gt;Hi, I can only apologise for what is probably about to be a stupid question! I have had a bit of a break from using SAS due to maternity leave and can't clear my head.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've used a macro to bucket a variable. The output is a table, which has two columns, min_score and max_score, and a row for each bucket:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;min_score&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;max_score&lt;/P&gt;&lt;P&gt;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&lt;/P&gt;&lt;P&gt;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 4&lt;/P&gt;&lt;P&gt;5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 6&lt;/P&gt;&lt;P&gt;7&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 27&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'd now like to apply that onto the dataset.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example I have the VALUE column and I want to apply a character variable called BUCKET based on the min and max values. I want it to look like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;VALUE BUCKET&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0-1&lt;/P&gt;&lt;P&gt;5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5-6&lt;/P&gt;&lt;P&gt;7&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;7-27&lt;/P&gt;&lt;P&gt;9&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;7-27&amp;nbsp;&lt;/P&gt;&lt;P&gt;5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5-6&lt;/P&gt;&lt;P&gt;6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5-6&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;where bucket is character. Is this possible? Am I making my life too complicated? Thanks for any input (be kind with a sleep deprived mummy please!)&lt;/P&gt;</description>
      <pubDate>Tue, 17 Sep 2019 10:39:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-two-columns-to-group-another-table/m-p/589302#M168529</guid>
      <dc:creator>beccab</dc:creator>
      <dc:date>2019-09-17T10:39:55Z</dc:date>
    </item>
    <item>
      <title>Re: Using two columns to group another table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-two-columns-to-group-another-table/m-p/589303#M168530</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/290780"&gt;@beccab&lt;/a&gt;&amp;nbsp;and welcome to the SAS Community (and back from maternity leave) &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;Use this as a template&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
    value range 0-1  = '0-1'
                  2  = '2'
                  3  = '3'
                  4  = '4'
                5-6  = '5-6'
                7-27 = '2-27'
    ;
run;

data have;
input value;
datalines;
1
5
7
9
5
6
3
;

data want;
    set have;
    bucket=put(value, range.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;VALUE BUCKET
1	  0-1
5	  5-6
7	  2-27
9	  2-27
5	  5-6
6	  5-6
3  	  3&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Feel free to ask if you have questions&lt;/P&gt;</description>
      <pubDate>Tue, 17 Sep 2019 10:46:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-two-columns-to-group-another-table/m-p/589303#M168530</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-09-17T10:46:35Z</dc:date>
    </item>
    <item>
      <title>Re: Using two columns to group another table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-two-columns-to-group-another-table/m-p/589304#M168531</link>
      <description>&lt;P&gt;If your first table is a SAS data set, you can also automate the creation of the format like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have1;
input min_score max_score;
datalines;
0 1
2 2
3 3
4 4
5 6
7 27
;

data fmt;
   length label $ 50;
   set have(rename=(min_score=start max_score=end)) end=lr;
   retain fmtname 'range' type 'n';
   label=catx('-', start, end);
   output;
   if lr then do;
      hlo='O';
      label='Unknown';
      output;
   end;
run;

proc format library=work cntlin=fmt;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And then use the same logic as before to create the desired output&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have2;
input value;
datalines;
1
5
7
9
5
6
3
;

data want;
    set have2;
    bucket=put(value, range.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Sep 2019 11:00:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-two-columns-to-group-another-table/m-p/589304#M168531</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-09-17T11:00:23Z</dc:date>
    </item>
    <item>
      <title>Re: Using two columns to group another table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-two-columns-to-group-another-table/m-p/589308#M168535</link>
      <description>&lt;P&gt;Thanks so much! I would probably (possibly) have got there eventually, but that helped get me going after picking up my old code and stumbling at the first hurdle! I should have said I'm going to be looping through and bucketing hundreds of columns, so the automated version is what I was after. Thanks for quick response&amp;nbsp;&lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Sep 2019 11:27:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-two-columns-to-group-another-table/m-p/589308#M168535</guid>
      <dc:creator>beccab</dc:creator>
      <dc:date>2019-09-17T11:27:55Z</dc:date>
    </item>
    <item>
      <title>Re: Using two columns to group another table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-two-columns-to-group-another-table/m-p/589310#M168536</link>
      <description>&lt;P&gt;Makes sense. Anytime. Glad you found your answer &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Sep 2019 11:29:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-two-columns-to-group-another-table/m-p/589310#M168536</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-09-17T11:29:01Z</dc:date>
    </item>
  </channel>
</rss>

