<?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: Clustering in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Clustering/m-p/363853#M86213</link>
    <description>&lt;P&gt;Yeah. Too many function name in my mind.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Latitude            Longitude;
id+1;
cards;
26.89155         75.82533
26.89156         75.82563
26.896437       75.827229
26.89111          75.819003
26.899911       75.813517
26.89716         75.813694
26.897943       75.813052
26.89255         75.813286
;
run;

proc sql;
select a.*,b.id as _id,geodist(a.Latitude,a.Longitude,b.Latitude,b.Longitude,'M') as dis
 from have as a,have as b
  where a.id ne b.id
  order by id,_id;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 02 Jun 2017 15:15:00 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2017-06-02T15:15:00Z</dc:date>
    <item>
      <title>Clustering</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Clustering/m-p/363757#M86174</link>
      <description>&lt;P&gt;My data looks like this:-&lt;/P&gt;&lt;P&gt;Latitude &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Longitude&lt;/P&gt;&lt;P&gt;26.89155 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 75.82533&lt;BR /&gt;26.89156 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 75.82563&lt;BR /&gt;26.896437 &amp;nbsp; &amp;nbsp; &amp;nbsp; 75.827229&lt;/P&gt;&lt;P&gt;26.89111 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;75.819003&lt;BR /&gt;26.899911 &amp;nbsp; &amp;nbsp; &amp;nbsp; 75.813517&lt;BR /&gt;26.89716 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 75.813694&lt;BR /&gt;26.897943 &amp;nbsp; &amp;nbsp; &amp;nbsp; 75.813052&lt;BR /&gt;26.89255 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 75.813286&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have to make clusters of areas with a radius of 250metres.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Jun 2017 11:14:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Clustering/m-p/363757#M86174</guid>
      <dc:creator>Himanshu007</dc:creator>
      <dc:date>2017-06-02T11:14:33Z</dc:date>
    </item>
    <item>
      <title>Re: Clustering</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Clustering/m-p/363781#M86183</link>
      <description>&lt;P&gt;So what would your output data look like?&lt;/P&gt;</description>
      <pubDate>Fri, 02 Jun 2017 12:50:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Clustering/m-p/363781#M86183</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2017-06-02T12:50:31Z</dc:date>
    </item>
    <item>
      <title>Re: Clustering</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Clustering/m-p/363790#M86188</link>
      <description>&lt;P&gt;Check GEODISTANCE() to get the distance between two points and use SQL to get what you want.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Jun 2017 13:10:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Clustering/m-p/363790#M86188</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-06-02T13:10:07Z</dc:date>
    </item>
    <item>
      <title>Re: Clustering</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Clustering/m-p/363828#M86209</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Check GEODISTANCE() to get the distance between two points and use SQL to get what you want.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Maybe GEODIST ?&lt;/P&gt;</description>
      <pubDate>Fri, 02 Jun 2017 14:24:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Clustering/m-p/363828#M86209</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-06-02T14:24:58Z</dc:date>
    </item>
    <item>
      <title>Re: Clustering</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Clustering/m-p/363853#M86213</link>
      <description>&lt;P&gt;Yeah. Too many function name in my mind.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Latitude            Longitude;
id+1;
cards;
26.89155         75.82533
26.89156         75.82563
26.896437       75.827229
26.89111          75.819003
26.899911       75.813517
26.89716         75.813694
26.897943       75.813052
26.89255         75.813286
;
run;

proc sql;
select a.*,b.id as _id,geodist(a.Latitude,a.Longitude,b.Latitude,b.Longitude,'M') as dis
 from have as a,have as b
  where a.id ne b.id
  order by id,_id;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 02 Jun 2017 15:15:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Clustering/m-p/363853#M86213</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-06-02T15:15:00Z</dc:date>
    </item>
    <item>
      <title>Re: Clustering</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Clustering/m-p/363988#M86261</link>
      <description>&lt;P&gt;Firstly Thanks a lot for your solution,&lt;/P&gt;&lt;P&gt;But the problem i m getting is that this solution makes the same input(lat,long) appear a number of times.&lt;/P&gt;&lt;P&gt;What I want is that points that form a cluster be grouped as cluster_1 and so on.&lt;/P&gt;&lt;P&gt;I hope you understand my problem.&lt;/P&gt;</description>
      <pubDate>Sat, 03 Jun 2017 07:22:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Clustering/m-p/363988#M86261</guid>
      <dc:creator>Himanshu007</dc:creator>
      <dc:date>2017-06-03T07:22:59Z</dc:date>
    </item>
    <item>
      <title>Re: Clustering</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Clustering/m-p/364002#M86266</link>
      <description>&lt;P&gt;OK. Here is .&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Latitude            Longitude;
id+1;
cards;
26.89155         75.82533
26.89156         75.82563
26.896437       75.827229
26.89111          75.819003
26.899911       75.813517
26.89716         75.813694
26.897943       75.813052
26.89255         75.813286
;
run;

proc sql;
create table temp as
select a.*,b.id as _id,
geodist(a.Latitude,a.Longitude,b.Latitude,b.Longitude,'k')*1000 as dis
 from have as a,have as b
  where a.id ne b.id and calculated dis &amp;lt; 250
  order by id,_id;
quit;
data have;
 set temp;
 call sortn(id,_id);
 keep id _id;
 rename id=from _id=to;
run;






/********Start to cluster***********/
data full;
  set have end=last;
  if _n_ eq 1 then do;
   declare hash h();
    h.definekey('node');
     h.definedata('node');
     h.definedone();
  end;
  output;
  node=from; h.replace();
  from=to; to=node;
  output;
  node=from; h.replace();
  if last then h.output(dataset:'node');
  drop node;
run;


data want(keep=node household);
declare hash ha(ordered:'a');
declare hiter hi('ha');
ha.definekey('count');
ha.definedata('last');
ha.definedone();
declare hash _ha(hashexp: 20);
_ha.definekey('key');
_ha.definedone();

if 0 then set full;
declare hash from_to(dataset:'full(where=(from is not missing and to is not missing))',hashexp:20,multidata:'y');
 from_to.definekey('from');
 from_to.definedata('to');
 from_to.definedone();

if 0 then set node;
declare hash no(dataset:'node');
declare hiter hi_no('no');
 no.definekey('node');
 no.definedata('node');
 no.definedone();
 

do while(hi_no.next()=0);
 household+1; output;
 count=1;
 key=node;_ha.add();
 last=node;ha.add();
 rc=hi.first();
 do while(rc=0);
   from=last;rx=from_to.find();
   do while(rx=0);
     key=to;ry=_ha.check();
      if ry ne 0 then do;
       node=to;output;rr=no.remove(key:node);
       key=to;_ha.add();
       count+1;
       last=to;ha.add();
      end;
      rx=from_to.find_next();
   end;
   rc=hi.next();
end;
ha.clear();_ha.clear();
end;
stop;
run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 03 Jun 2017 10:45:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Clustering/m-p/364002#M86266</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-06-03T10:45:11Z</dc:date>
    </item>
  </channel>
</rss>

