<?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: Group observations from a column in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Group-observations-from-a-column/m-p/502357#M134098</link>
    <description>&lt;P&gt;Kiran V,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you. I followed the lookup table advise to address the issue. I appreciate your help.&lt;/P&gt;</description>
    <pubDate>Mon, 08 Oct 2018 11:49:43 GMT</pubDate>
    <dc:creator>msastry</dc:creator>
    <dc:date>2018-10-08T11:49:43Z</dc:date>
    <item>
      <title>Group observations from a column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Group-observations-from-a-column/m-p/501137#M133584</link>
      <description>&lt;P&gt;Is there a way to group nominal observations from a column to create a new variable?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Month Customer_ID Merchant&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Amount&amp;nbsp; &amp;nbsp; Count&lt;/P&gt;&lt;P&gt;Apr-18 12345&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Walmart&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;$20.00&amp;nbsp; &amp;nbsp; &amp;nbsp;5&lt;/P&gt;&lt;P&gt;Apr-18 23456&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Exxon&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $35.00&amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;May-18 67891&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Home Depot&amp;nbsp; $60.14&amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;/P&gt;&lt;P&gt;May-18 34567&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Lowes&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $1200&amp;nbsp; &amp;nbsp; &amp;nbsp;5&lt;/P&gt;&lt;P&gt;Jun-18&amp;nbsp; 45678&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Shell&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;$25.00&amp;nbsp; &amp;nbsp; 3&lt;/P&gt;&lt;P&gt;Jun-18&amp;nbsp; 56789&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;McDonalds&amp;nbsp; &amp;nbsp; &amp;nbsp;$10.00&amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the above example, if I would like to create a new column 'Category' that has all gas charges as Gas (Exxon, Shell), all home improvement charges as Home Improvement (Lowes, Home Depot), Restaurants (McDonalds) from the above example.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The issue is that there are ~5000 merchants in several months of data and is there an optimum way to group these into specific categories for further analysis/reporting/analytics?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&amp;nbsp; &amp;nbsp;&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>Wed, 03 Oct 2018 14:01:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Group-observations-from-a-column/m-p/501137#M133584</guid>
      <dc:creator>msastry</dc:creator>
      <dc:date>2018-10-03T14:01:43Z</dc:date>
    </item>
    <item>
      <title>Re: Group observations from a column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Group-observations-from-a-column/m-p/501143#M133586</link>
      <description>&lt;P&gt;Start with putting your relationships merchant-category into a dataset. Create a format from that dataset, and use it to create the category variable when you need it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit: see some example code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data lookup;
infile cards dlm=',';
input merchant :$20. category :$20.;
cards;
Walmart,Retail
Exxon,Gas
Home Depot,Home Improvement
Lowes,Home Improvement
Shell,Gas
McDonalds,Restaurants
;
run;

data cntlin;
set lookup (rename=(merchant=start category=label));
fmtname = 'category';
type = 'C';
run;

proc format cntlin=cntlin;
run;

data have;
infile cards dlm=',';
input month $ customer_id $ merchant :$20. amount count;
category = put(merchant,$category.);
cards;
Apr-18,12345,Walmart,20,5
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 03 Oct 2018 14:14:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Group-observations-from-a-column/m-p/501143#M133586</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-10-03T14:14:23Z</dc:date>
    </item>
    <item>
      <title>Re: Group observations from a column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Group-observations-from-a-column/m-p/501149#M133589</link>
      <description>&lt;P&gt;In my view, best way is to have a lookup table, something like below and then picking up category by doing join on Merchant&lt;/P&gt;
&lt;P&gt;You can update or add to lookup on regular basis. This helps to maintain things easily.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Merchant&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Category&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Exxon&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; &amp;nbsp;Gas&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Shell&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; &amp;nbsp; &amp;nbsp;Gas&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Lowes&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; Home Improvement&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Home Depot&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Home Improvement&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Oct 2018 14:20:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Group-observations-from-a-column/m-p/501149#M133589</guid>
      <dc:creator>kiranv_</dc:creator>
      <dc:date>2018-10-03T14:20:07Z</dc:date>
    </item>
    <item>
      <title>Re: Group observations from a column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Group-observations-from-a-column/m-p/501152#M133592</link>
      <description>&lt;P&gt;Thank you, Mr. KurtBremser. I appreciate your quick response.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Just to clarify, did you mean to say I have to have a separate dataset that has 2 columns: 1. Category, and 2. Merchant?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As the number of merchants are ~5000 in multiple categories, if there is a way to optimize adding the category column that has multiple merchants? Also, the list of merchants per category could be dynamic as the customers could go to new merchants to do their shopping, so the new merchants need to be added if they do not exist in the current dataset.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Oct 2018 14:20:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Group-observations-from-a-column/m-p/501152#M133592</guid>
      <dc:creator>msastry</dc:creator>
      <dc:date>2018-10-03T14:20:38Z</dc:date>
    </item>
    <item>
      <title>Re: Group observations from a column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Group-observations-from-a-column/m-p/501166#M133594</link>
      <description>&lt;P&gt;Setting up the lookup dataset is of course initial work, but once you have it, you have it, and it only needs maintenance. And it keeps data out of code.&lt;/P&gt;
&lt;P&gt;And how does a customer changing merchants influence that merchant's category? That's &lt;A href="https://www.youtube.com/watch?v=mdf25VY8RYA" target="_blank"&gt;highly illogical&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Oct 2018 14:51:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Group-observations-from-a-column/m-p/501166#M133594</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-10-03T14:51:23Z</dc:date>
    </item>
    <item>
      <title>Re: Group observations from a column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Group-observations-from-a-column/m-p/502356#M134097</link>
      <description>&lt;P&gt;Hi Mr. KurtBremser,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I finally used your idea on the lookup table. I appreciate your help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Oct 2018 11:48:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Group-observations-from-a-column/m-p/502356#M134097</guid>
      <dc:creator>msastry</dc:creator>
      <dc:date>2018-10-08T11:48:46Z</dc:date>
    </item>
    <item>
      <title>Re: Group observations from a column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Group-observations-from-a-column/m-p/502357#M134098</link>
      <description>&lt;P&gt;Kiran V,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you. I followed the lookup table advise to address the issue. I appreciate your help.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Oct 2018 11:49:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Group-observations-from-a-column/m-p/502357#M134098</guid>
      <dc:creator>msastry</dc:creator>
      <dc:date>2018-10-08T11:49:43Z</dc:date>
    </item>
  </channel>
</rss>

