<?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: Classfication in SAS EG in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Classfication-in-SAS-EG/m-p/460243#M29679</link>
    <description>&lt;P&gt;Not sure what you want to achieve. If you want a report on each customer on number of class items then here is one type of approach.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA HAVE;
INPUT CUSTOMER_ID :$ GOOD_DESCRIPTION :$;
DATALINES;
01 Cotton
01 Banana
02 Silk
03 Yarn
03 Apple
03 Cotton
03 Banana
04 Banana
;
RUN;

DATA Class_ID;
set have ;
IF GOOD_DESCRIPTION in ("Cotton","Silk","Yarn") THEN CLASS=1;
ELSE class=2;
run;
PROC SORT DATA=Class_ID;
by customer_id class;
run;
data Class_ID_Count(drop=good_description);
Set Class_ID;
by customer_id class;
if first.class then count=1;
else count+1;
if last.class;
run;

proc transpose data=Class_ID_Count out=want(Drop=_name_) prefix=Class_;
by customer_id;
id class;
var count;
run;
data want;
set want;
array num _numeric_;
do over num;
if num=. then num=0;
end;
run;
proc print data=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 05 May 2018 12:19:26 GMT</pubDate>
    <dc:creator>SuryaKiran</dc:creator>
    <dc:date>2018-05-05T12:19:26Z</dc:date>
    <item>
      <title>Classfication in SAS EG</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Classfication-in-SAS-EG/m-p/460239#M29678</link>
      <description>&lt;P&gt;Hi Community,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a set of transaction data with the following columns: Good_description, Customer_ID&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As usual in the classification I defined my classes before. So that I have (in this example) 2 different classes. Class 1 is for textile goods und Class 2 is for fruits&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Good_description: cotton , Customer_ID = 01&amp;nbsp;&lt;/P&gt;&lt;P&gt;Good_description: banana&amp;nbsp;, Customer_ID = 01&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to build a classification, where I can identify customers, who buy goods from two different classes.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. question: Does it makes sense to build a decision tree here, if yes how can I produce one?&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. question Which possibilities do I have in SAS EG to realize?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Mairam&lt;/P&gt;</description>
      <pubDate>Sat, 05 May 2018 11:02:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Classfication-in-SAS-EG/m-p/460239#M29678</guid>
      <dc:creator>Mairam2345</dc:creator>
      <dc:date>2018-05-05T11:02:05Z</dc:date>
    </item>
    <item>
      <title>Re: Classfication in SAS EG</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Classfication-in-SAS-EG/m-p/460243#M29679</link>
      <description>&lt;P&gt;Not sure what you want to achieve. If you want a report on each customer on number of class items then here is one type of approach.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA HAVE;
INPUT CUSTOMER_ID :$ GOOD_DESCRIPTION :$;
DATALINES;
01 Cotton
01 Banana
02 Silk
03 Yarn
03 Apple
03 Cotton
03 Banana
04 Banana
;
RUN;

DATA Class_ID;
set have ;
IF GOOD_DESCRIPTION in ("Cotton","Silk","Yarn") THEN CLASS=1;
ELSE class=2;
run;
PROC SORT DATA=Class_ID;
by customer_id class;
run;
data Class_ID_Count(drop=good_description);
Set Class_ID;
by customer_id class;
if first.class then count=1;
else count+1;
if last.class;
run;

proc transpose data=Class_ID_Count out=want(Drop=_name_) prefix=Class_;
by customer_id;
id class;
var count;
run;
data want;
set want;
array num _numeric_;
do over num;
if num=. then num=0;
end;
run;
proc print data=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 05 May 2018 12:19:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Classfication-in-SAS-EG/m-p/460243#M29679</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-05-05T12:19:26Z</dc:date>
    </item>
    <item>
      <title>Re: Classfication in SAS EG</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Classfication-in-SAS-EG/m-p/460278#M29682</link>
      <description>&lt;P&gt;Following &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/83078"&gt;@SuryaKiran&lt;/a&gt;'s appoach, and an alternative&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA TRANSACT;
INPUT CUSTOMER_ID $ GOOD_DESCRIPTION $;
DATALINES;
01 Cotton
01 Banana
02 Silk
03 Yarn
03 Apple
03 Cotton
03 Banana
04 Banana
04 Barley
;

data CLASS;
input class GOOD_DESCRIPTION $;
datalines;
1 Cotton
1 Silk
1 Yarn
0 Apple
0 Banana
0 Pear
;

proc sql;
create table TRANSACT_CLASS as
select 
    CUSTOMER_ID,
    coalesce( class, 999) as class,
    count(*) as nbTransact
from 
    TRANSACT as T left join
    CLASS as C on T.GOOD_DESCRIPTION=C.GOOD_DESCRIPTION
group by CUSTOMER_ID, class;
quit;

proc transpose data=TRANSACT_CLASS 
    out=CUSTOMER_CLASS(drop=_name_) prefix=class_;
by CUSTOMER_ID;
var nbTransact;
id class;
run;

proc print data=CUSTOMER_CLASS noobs; run;

/* Or With a format and proc freq, get the proportions (Probably faster) */

proc format;
value $good_class
"Cotton" = "1"
"Silk"   = "1"
"Yarn"   = "1"
"Apple"  = "0"
"Banana" = "0"
"Pear"   = "0"
other    = "999";
run;

proc freq data=TRANSACT noprint;
format GOOD_DESCRIPTION $good_class.;
table customer_id*good_description / out=class_pct outpct;
run;

proc transpose data=class_pct 
    out=CUSTOMER_CLASS_PCT(drop=_name_ _label_) prefix=class_;
by CUSTOMER_ID;
var pct_row;
format pct_row 4.1;
id good_description;
run;

proc print data=CUSTOMER_CLASS_PCT noobs; run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 06 May 2018 04:09:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Classfication-in-SAS-EG/m-p/460278#M29682</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-05-06T04:09:46Z</dc:date>
    </item>
  </channel>
</rss>

