<?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 Proc fastclus, proc sgplot how to create a plot with the best means and cluster assignments in Statistical Procedures</title>
    <link>https://communities.sas.com/t5/Statistical-Procedures/Proc-fastclus-proc-sgplot-how-to-create-a-plot-with-the-best/m-p/653913#M31522</link>
    <description>&lt;P&gt;Hello, I'm trying to make banks clients segmentation and I failed in making some plots. Not working properly code is bold. Please help me.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&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="preview of standrazied dataset" style="width: 903px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/40598iB6ED58B55465860C/image-size/large?v=v2&amp;amp;px=999" role="button" title="Przechwytywanie.PNG" alt="preview of standrazied dataset" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;preview of standrazied dataset&lt;/span&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="distribution of RMSE - wrong" style="width: 675px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/40599i739DF7B98A0C4BF2/image-size/large?v=v2&amp;amp;px=999" role="button" title="Przechwytywanie1.PNG" alt="distribution of RMSE - wrong" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;distribution of RMSE - wrong&lt;/span&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Also not correct" style="width: 672px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/40600i87399D99A83C1398/image-size/large?v=v2&amp;amp;px=999" role="button" title="Przechwytywanie2.PNG" alt="Also not correct" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Also not correct&lt;/span&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Super wrong cluster plot" style="width: 673px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/40601i0720335F3E2B5265/image-size/large?v=v2&amp;amp;px=999" role="button" title="Przechwytywanie3.PNG" alt="Super wrong cluster plot" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Super wrong cluster plot&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc stdize data=dane out=Stand method=std;
var Duration Age Credit_amount;
run;



/* k-means*/
proc fastclus data=Stand out=Clust
maxclusters=5 maxiter=100;
var Duration Age Credit_amount;
run;

proc freq data=Clust;
tables Purpose*Cluster;
run;



/*Definition of a macro program called multseed, which takes the number of initial measures as the argument.&amp;nbsp; It allows to find several cluster solutions with different starting points*/
Title "Multseed macro for finding multiple 
cluster solutions with different starting seeds";
%macro multseed(n);
%do i = 1 %to &amp;amp;n;
proc surveyselect data=Clust out=seeds n=5
seed=&amp;amp;i noprint;
run;

proc fastclus data=Clust maxc=5 converge=0
drift seeds=seeds outstat=out least=2
noprint mean=meanout;
var Duration Age Credit_amount;
run;

data out;
set out (where=(_type_="WITHIN_STD"));
seed=&amp;amp;i;
run;

data ans;
set out
%if &amp;amp;i&amp;gt;1 %then %do; 
ans
%end;
;
keep seed over_all Duration Age Credit_amount;
run;
%end;
%mend;


/*Using multseed with n=100*/
%multseed(100);




/*Comparative analysis of results for 100 segmentation models from different starting seeds*/
proc univariate data=ans plot;
var OVER_ALL;
id seed;
run;


/* it's not working */
/*Building a histogram of RMSE values for 100 different solutions of&amp;nbsp; the K-means method at different starting points*/
Title "Distribution of RMSE";
proc sgplot data=ans;
histogram over_all / scale=count binwidth=.01;
xaxis display=(nolabel);
run;



/*Building a scatter plot of estimated cluster centers for 100 different solutions of the K-means method at various start points*/
Title "Estimated cluster centers of 100 different K-means solutions";
proc sgplot data=ans;
scatter x=Duration y=Credit_amount;
run;

/*Best solution out of 100 seeds*/ 
Title "Best solution out of 100 seeds";
proc surveyselect data=Stand out=seeds n=5 seed=66;
run;
proc fastclus data=Stand maxc=5 converge=0 drift seed=seeds
outstat=out least=2 mean=meanout out=asgn;
var Duration Age Credit_amount;
run;


/* THIS IS NOT WORKING PROPERLY */

/*Creating a chart showing average clusters and assignments to them as part of the best solution*/
Title "Plot with the best means and cluster assignments";
data clusout;
set asgn meanout 
(keep=Duration Age Credit_amount);
length clus $6.;
if cluster=. then clus="Center";
else clus=put(cluster, $1.);
label clus="Cluster";
run;
data myanno;
drawspace='datavalue'; function='line';
x1=-.1; y1=3.5; x2=4.5; y2=3.5; output;
x1=4.5; y1=4.5; x2=7.1; y2=4.5; output;
run;
proc sgplot data=clusout sganno=myanno;
scatter x=Duration y=Credit_amount / group=clus;
refline 4.5 / axis=x;
lineparm x=2.5 y=0 slope=-1;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 06 Jun 2020 18:08:54 GMT</pubDate>
    <dc:creator>sasowiczka123</dc:creator>
    <dc:date>2020-06-06T18:08:54Z</dc:date>
    <item>
      <title>Proc fastclus, proc sgplot how to create a plot with the best means and cluster assignments</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Proc-fastclus-proc-sgplot-how-to-create-a-plot-with-the-best/m-p/653913#M31522</link>
      <description>&lt;P&gt;Hello, I'm trying to make banks clients segmentation and I failed in making some plots. Not working properly code is bold. Please help me.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&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="preview of standrazied dataset" style="width: 903px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/40598iB6ED58B55465860C/image-size/large?v=v2&amp;amp;px=999" role="button" title="Przechwytywanie.PNG" alt="preview of standrazied dataset" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;preview of standrazied dataset&lt;/span&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="distribution of RMSE - wrong" style="width: 675px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/40599i739DF7B98A0C4BF2/image-size/large?v=v2&amp;amp;px=999" role="button" title="Przechwytywanie1.PNG" alt="distribution of RMSE - wrong" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;distribution of RMSE - wrong&lt;/span&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Also not correct" style="width: 672px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/40600i87399D99A83C1398/image-size/large?v=v2&amp;amp;px=999" role="button" title="Przechwytywanie2.PNG" alt="Also not correct" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Also not correct&lt;/span&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Super wrong cluster plot" style="width: 673px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/40601i0720335F3E2B5265/image-size/large?v=v2&amp;amp;px=999" role="button" title="Przechwytywanie3.PNG" alt="Super wrong cluster plot" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Super wrong cluster plot&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc stdize data=dane out=Stand method=std;
var Duration Age Credit_amount;
run;



/* k-means*/
proc fastclus data=Stand out=Clust
maxclusters=5 maxiter=100;
var Duration Age Credit_amount;
run;

proc freq data=Clust;
tables Purpose*Cluster;
run;



/*Definition of a macro program called multseed, which takes the number of initial measures as the argument.&amp;nbsp; It allows to find several cluster solutions with different starting points*/
Title "Multseed macro for finding multiple 
cluster solutions with different starting seeds";
%macro multseed(n);
%do i = 1 %to &amp;amp;n;
proc surveyselect data=Clust out=seeds n=5
seed=&amp;amp;i noprint;
run;

proc fastclus data=Clust maxc=5 converge=0
drift seeds=seeds outstat=out least=2
noprint mean=meanout;
var Duration Age Credit_amount;
run;

data out;
set out (where=(_type_="WITHIN_STD"));
seed=&amp;amp;i;
run;

data ans;
set out
%if &amp;amp;i&amp;gt;1 %then %do; 
ans
%end;
;
keep seed over_all Duration Age Credit_amount;
run;
%end;
%mend;


/*Using multseed with n=100*/
%multseed(100);




/*Comparative analysis of results for 100 segmentation models from different starting seeds*/
proc univariate data=ans plot;
var OVER_ALL;
id seed;
run;


/* it's not working */
/*Building a histogram of RMSE values for 100 different solutions of&amp;nbsp; the K-means method at different starting points*/
Title "Distribution of RMSE";
proc sgplot data=ans;
histogram over_all / scale=count binwidth=.01;
xaxis display=(nolabel);
run;



/*Building a scatter plot of estimated cluster centers for 100 different solutions of the K-means method at various start points*/
Title "Estimated cluster centers of 100 different K-means solutions";
proc sgplot data=ans;
scatter x=Duration y=Credit_amount;
run;

/*Best solution out of 100 seeds*/ 
Title "Best solution out of 100 seeds";
proc surveyselect data=Stand out=seeds n=5 seed=66;
run;
proc fastclus data=Stand maxc=5 converge=0 drift seed=seeds
outstat=out least=2 mean=meanout out=asgn;
var Duration Age Credit_amount;
run;


/* THIS IS NOT WORKING PROPERLY */

/*Creating a chart showing average clusters and assignments to them as part of the best solution*/
Title "Plot with the best means and cluster assignments";
data clusout;
set asgn meanout 
(keep=Duration Age Credit_amount);
length clus $6.;
if cluster=. then clus="Center";
else clus=put(cluster, $1.);
label clus="Cluster";
run;
data myanno;
drawspace='datavalue'; function='line';
x1=-.1; y1=3.5; x2=4.5; y2=3.5; output;
x1=4.5; y1=4.5; x2=7.1; y2=4.5; output;
run;
proc sgplot data=clusout sganno=myanno;
scatter x=Duration y=Credit_amount / group=clus;
refline 4.5 / axis=x;
lineparm x=2.5 y=0 slope=-1;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 06 Jun 2020 18:08:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Proc-fastclus-proc-sgplot-how-to-create-a-plot-with-the-best/m-p/653913#M31522</guid>
      <dc:creator>sasowiczka123</dc:creator>
      <dc:date>2020-06-06T18:08:54Z</dc:date>
    </item>
    <item>
      <title>Re: Proc fastclus, proc sgplot how to create a plot with the best means and cluster assignments</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Proc-fastclus-proc-sgplot-how-to-create-a-plot-with-the-best/m-p/657935#M31523</link>
      <description>&lt;P&gt;Moved to the &lt;EM&gt;procedures&lt;/EM&gt; forum.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jun 2020 06:50:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Proc-fastclus-proc-sgplot-how-to-create-a-plot-with-the-best/m-p/657935#M31523</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-06-12T06:50:35Z</dc:date>
    </item>
    <item>
      <title>Re: Proc fastclus, proc sgplot how to create a plot with the best means and cluster assignments</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Proc-fastclus-proc-sgplot-how-to-create-a-plot-with-the-best/m-p/658124#M31528</link>
      <description>&lt;P&gt;&amp;nbsp;It is very difficult to identify an error from the statement "This is not working properly."&amp;nbsp; What errors, warnings and notes are in the log? Is the plot that is produced somehow not what was expected?&amp;nbsp; If that is the case, tell us what&amp;nbsp;&lt;EM&gt;&lt;U&gt;is&lt;/U&gt;&lt;/EM&gt; expected (or at least is wanted).&amp;nbsp; With these pieces of information, we are in a much better place for providing tips/guidance/other code that may be useful.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SteveDenham&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jun 2020 17:10:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Proc-fastclus-proc-sgplot-how-to-create-a-plot-with-the-best/m-p/658124#M31528</guid>
      <dc:creator>SteveDenham</dc:creator>
      <dc:date>2020-06-12T17:10:17Z</dc:date>
    </item>
  </channel>
</rss>

