<?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: SAS: unique identifier for multiple columns with same values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-unique-identifier-for-multiple-columns-with-same-values/m-p/520376#M141091</link>
    <description>&lt;P&gt;This is close but I'm seeing errors if I input additional rows to test. Take the following example where I've added Customer X Device 5:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
    length cust dev $5;
    input cust $ dev $;
    datalines;
    a   1
    a   2
    a   7
    b   2
    b   3
    c   3
    d   4
    e   5
    h   2
    x   4
    x   5
    ;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Your code provides the following results:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;d	4	UID2
x	4	UID2
e	5	UID3
x	5	UID3&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;However, these should all have the same value of UID2 because Customer X is linked to Devices 4 and 5 which should also link Customer E and D.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 11 Dec 2018 14:42:46 GMT</pubDate>
    <dc:creator>kilo_foxtrot</dc:creator>
    <dc:date>2018-12-11T14:42:46Z</dc:date>
    <item>
      <title>SAS: unique identifier for multiple columns with same values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-unique-identifier-for-multiple-columns-with-same-values/m-p/519970#M140941</link>
      <description>&lt;P&gt;Take the example code below containing customers and their devices:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
    length cust dev $5;
    input cust $ dev $;
    datalines;
    a   1
    a   2
    a   7
    b   2
    b   3
    c   3
    d   4
    e   5
    h   2
    x   4
    ;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I'm trying to group ALL related individuals by customer and device into unique IDs. For example, Customer A is related to Customer B through Device 2, and Customer B is related to Customer C through Device 3. Because A is related to B and B is related to C, these should have the same UID.&amp;nbsp;&lt;SPAN&gt;If you think of customer as the 'parent' and device as the 'child' in node structure, all linked children and parents should be in the same UID. Any breaks should be separate UIDs.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is the desired output:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Customer|Device|UID
    a       1   UID1
    a       2   UID1
    a       7   UID1
    b       2   UID1
    b       3   UID1
    c       3   UID1
    h       2   UID1
    d       4   UID2
    x	    4	UID2
    e       5   UID3&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I have tried transposing by Customer and doing a 'cascade' retain on customer and device but the code gets pretty hairy. Also, I do not have access to PROC BOM which I've read may help my case. Does anyone have any ideas on how this might be achieved?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Dec 2018 14:29:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-unique-identifier-for-multiple-columns-with-same-values/m-p/519970#M140941</guid>
      <dc:creator>kilo_foxtrot</dc:creator>
      <dc:date>2018-12-10T14:29:47Z</dc:date>
    </item>
    <item>
      <title>Re: SAS: unique identifier for multiple columns with same values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-unique-identifier-for-multiple-columns-with-same-values/m-p/520021#M140958</link>
      <description>&lt;P&gt;You will need to keep two hash objects to keep track of already assigned uid's:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
    length cust dev $5;
    input cust $ dev $;
    datalines;
    a   1
    a   2
    a   7
    b   2
    b   3
    c   3
    d   4
    e   5
    h   2
    x   4
    ;
run;

data want;
set have end=eof;
length uid $4;
retain counter 0;
if _n_ = 1
then do;
  declare hash devices();
  devices.definedata("uid",'dev');
  devices.definekey("dev");
  devices.definedone();
  declare hash customers();
  customers.definedata("uid",'cust');
  customers.definekey("cust");
  customers.definedone();
  call missing(uid);
end;
if customers.find()
then do;
  if devices.find()
  then do;
    counter + 1;
    uid = 'UID' !! put(counter,1.);
    rc = devices.add();
    rc = customers.add();
  end;
  else rc = customers.add();
end;
else do;
  if devices.find() then rc = devices.add();
end;
drop rc counter;
run;

proc sort data=want;
by uid cust;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 10 Dec 2018 15:59:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-unique-identifier-for-multiple-columns-with-same-values/m-p/520021#M140958</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-12-10T15:59:36Z</dc:date>
    </item>
    <item>
      <title>Re: SAS: unique identifier for multiple columns with same values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-unique-identifier-for-multiple-columns-with-same-values/m-p/520110#M140993</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
    length cust dev $5;
    input cust $ dev $;
    datalines;
    a   1
    a   2
    a   7
    b   2
    b   3
    c   3
    d   4
    e   5
    h   2
    x   4
    ;
run;

data _null_;
if _n_=1 then do;
  dcl hash H (multidata:'yes') ;
   h.definekey  ("dev") ;
   h.definedata ("cust","dev","uid") ;
   h.definedone () ;
end;
do until(last.cust);
set have end=l;
by cust;
if _n_=1 then  do;
c=_n_;
uid =cats( 'UID', put(c,8. -l));
rc=h.add();
end;
else if not f and h.find()=0 then f=1;
end;
do until(last.cust);
set have ;
by cust;                             
if _n_&amp;gt;1 then do;
if f then rc=h.add();
else do;
if first.cust then do;c+1; uid =cats( 'UID', put(c,8. -l));end;
rc=h.add();
end;
end;
end;
if l then h.output(dataset:'want');
run;


proc sort data=want;
by uid cust dev;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 10 Dec 2018 20:20:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-unique-identifier-for-multiple-columns-with-same-values/m-p/520110#M140993</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-12-10T20:20:14Z</dc:date>
    </item>
    <item>
      <title>Re: SAS: unique identifier for multiple columns with same values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-unique-identifier-for-multiple-columns-with-same-values/m-p/520376#M141091</link>
      <description>&lt;P&gt;This is close but I'm seeing errors if I input additional rows to test. Take the following example where I've added Customer X Device 5:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
    length cust dev $5;
    input cust $ dev $;
    datalines;
    a   1
    a   2
    a   7
    b   2
    b   3
    c   3
    d   4
    e   5
    h   2
    x   4
    x   5
    ;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Your code provides the following results:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;d	4	UID2
x	4	UID2
e	5	UID3
x	5	UID3&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;However, these should all have the same value of UID2 because Customer X is linked to Devices 4 and 5 which should also link Customer E and D.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Dec 2018 14:42:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-unique-identifier-for-multiple-columns-with-same-values/m-p/520376#M141091</guid>
      <dc:creator>kilo_foxtrot</dc:creator>
      <dc:date>2018-12-11T14:42:46Z</dc:date>
    </item>
    <item>
      <title>Re: SAS: unique identifier for multiple columns with same values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-unique-identifier-for-multiple-columns-with-same-values/m-p/520377#M141092</link>
      <description>Your answer is also very close but provides inaccuracies in the last four rows in the new test data in my reply above.</description>
      <pubDate>Tue, 11 Dec 2018 14:44:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-unique-identifier-for-multiple-columns-with-same-values/m-p/520377#M141092</guid>
      <dc:creator>kilo_foxtrot</dc:creator>
      <dc:date>2018-12-11T14:44:26Z</dc:date>
    </item>
    <item>
      <title>Re: SAS: unique identifier for multiple columns with same values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-unique-identifier-for-multiple-columns-with-same-values/m-p/520397#M141101</link>
      <description>&lt;P&gt;I realize my mistake, a bit busy now but will try later&lt;/P&gt;</description>
      <pubDate>Tue, 11 Dec 2018 15:23:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-unique-identifier-for-multiple-columns-with-same-values/m-p/520397#M141101</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-12-11T15:23:41Z</dc:date>
    </item>
    <item>
      <title>Re: SAS: unique identifier for multiple columns with same values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-unique-identifier-for-multiple-columns-with-same-values/m-p/520896#M141285</link>
      <description>Thank you -- I appreciate your efforts! I apologize I do not have an in-depth knowledge of hashes in SAS so I am unable to troubleshoot your first answer.</description>
      <pubDate>Wed, 12 Dec 2018 16:39:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-unique-identifier-for-multiple-columns-with-same-values/m-p/520896#M141285</guid>
      <dc:creator>kilo_foxtrot</dc:creator>
      <dc:date>2018-12-12T16:39:37Z</dc:date>
    </item>
    <item>
      <title>Re: SAS: unique identifier for multiple columns with same values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-unique-identifier-for-multiple-columns-with-same-values/m-p/520907#M141291</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/250583"&gt;@kilo_foxtrot&lt;/a&gt;&amp;nbsp; Don't worry about technology. I am working on your thread by seeking help from my college mate(who is super smart and solved the same in python)&amp;nbsp; in handling networking problems. Once he gives me the understanding i need, I will try to code in SAS. No need to apologize. I love learning.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Dec 2018 17:03:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-unique-identifier-for-multiple-columns-with-same-values/m-p/520907#M141291</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-12-12T17:03:17Z</dc:date>
    </item>
    <item>
      <title>Re: SAS: unique identifier for multiple columns with same values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-unique-identifier-for-multiple-columns-with-same-values/m-p/521057#M141339</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/250583"&gt;@kilo_foxtrot&lt;/a&gt;&amp;nbsp; First off, Sorry for the delay as I was consumed with a lot of my own stuff to do. Please see if the following works and let me know. I can further simplify and eliminate some redundancies. Right now, it is 10:10PM at Chicago and I am leaning on my pillows laying with my laptop in my lap. Feeling so tired,&amp;nbsp; I haven't made it a complete neat one. Yet, I wanted to keep up my word and here you go-&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Your new updated dataset HAVE*/
data have;
    length cust dev $5;
    input cust $ dev $;
    datalines;
    a   1
    a   2
    a   7
    b   2
    b   3
    c   3
    d   4
    e   5
    h   2
    x   4
    x   5
    ;
run;
dm log 'clear';
/*Intial look up*/
data _null_;
if _n_=1 then do;
length uid __dev __cust $5;
if 0 then set have(rename=(dev=_dev cust=_cust));
  declare hash H (multidata:'yes') ;
   h.definekey  ("__cust") ;
   h.definedata ("__cust","__dev","uid") ;
   h.definedone () ;
   declare hash H1 (dataset:'have(rename=(dev=_dev cust=_cust))', multidata:'yes') ;
   h1.definekey  ("_dev") ;
   h1.definedata ("_cust","_dev") ;
   h1.definedone () ;
   declare hiter hi('h');
   declare hiter hh('h1');
   call missing(__cust,__dev);
end;
array t(999) $5;
n=0;
do until(last.cust);
	set have end=l;
	by cust;
	if first.cust then 
		do;
			if h.find(key:cust) = 0 then f1=1;
			do while(hi.next()=0);
			if dev=__dev	then do; f2=1;leave;end;
			end;
			if sum(f1, f2)=. then do;c+1;uid =cats( 'UID', put(c,8. -l)); end;
		end;
	if not f1 then do rc1=h1.find(key:dev) by 0 while(rc1=0);
		rc=h.add(key:_cust,data:_cust,data: _dev,data:uid);
		if _cust ne cust then do;
		n+1;
		t(n)=_cust;
		end;
		rc1=h1.find_next();
	end;
end;
if not f1 then do i=1 to dim(t);
	if not missing(t(i)) then 
	do while(hh.next()=0);
	if t(i)=_cust then rc=h.add(key:_cust,data:_cust,data: _dev,data:uid);
	end;
end;
if l then h.output(dataset:'w');
run;

/*Final Want	*/
proc sort data=w out=want nodupkey;
by uid __cust __dev;
run;


&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please do let me know. And I will try to see to make some improvements when I feel fresh hopefully after a good sleep. Good night!&lt;/P&gt;</description>
      <pubDate>Thu, 13 Dec 2018 16:56:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-unique-identifier-for-multiple-columns-with-same-values/m-p/521057#M141339</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-12-13T16:56:13Z</dc:date>
    </item>
    <item>
      <title>Re: SAS: unique identifier for multiple columns with same values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-unique-identifier-for-multiple-columns-with-same-values/m-p/521225#M141400</link>
      <description>&lt;P&gt;No need at all to apologize -- this is on your time! If I add Customer A Device 5, it should link every single record to be UID1. Your latest code doesn't quite get this right and it also adds two addition rows to the data:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Your new updated dataset HAVE -- new cust x dev 5*/
data have;
length cust dev $5;
input cust $ dev $;
datalines;
a 1
a 2
a 5
a 7
b 2
b 3
c 3
d 4
e 5
h 2
x 4
x 5
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;__cust	__dev	uid
a	1	UID1
a	2	UID1
a	5	UID1
a	7	UID1
b	2	UID1
b	3	UID1
c	3	UID1
e	5	UID1
h	2	UID1
x	4	UID1
x	5	UID1
d	4	UID2
x	4	UID2
x	5	UID2&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can't thank you enough for your continued efforts on this -- it is getting very complex!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Dec 2018 17:59:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-unique-identifier-for-multiple-columns-with-same-values/m-p/521225#M141400</guid>
      <dc:creator>kilo_foxtrot</dc:creator>
      <dc:date>2018-12-13T17:59:51Z</dc:date>
    </item>
    <item>
      <title>Re: SAS: unique identifier for multiple columns with same values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-unique-identifier-for-multiple-columns-with-same-values/m-p/521236#M141402</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/250583"&gt;@kilo_foxtrot&lt;/a&gt;&amp;nbsp; Thank you. I request your patience(which you are, just saying again&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;&amp;nbsp; ) while we do this interactively and at the sametime I work on my stuff too. Trust me, yours is more interesting than mine and how i wish I devoted more time to test.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Nevetheless, I did a minor change and will wait for your feedback for further changes yet again&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's clear you are awesome in testing and that helps.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Your new updated dataset HAVE -- new cust x dev 5*/
data have;
length cust dev $5;
input cust $ dev $;
datalines;
a 1
a 2
a 5
a 7
b 2
b 3
c 3
d 4
e 5
h 2
x 4
x 5
;
run;





dm log 'clear';
/*Intial look up*/
data _null_;
if _n_=1 then do;
length uid __dev __cust $5;
if 0 then set have(rename=(dev=_dev cust=_cust));
  declare hash H (multidata:'yes') ;
   h.definekey  ("__cust") ;
   h.definedata ("__cust","__dev","uid") ;
   h.definedone () ;
   declare hash H1 (dataset:'have(rename=(dev=_dev cust=_cust))', multidata:'yes') ;
   h1.definekey  ("_dev") ;
   h1.definedata ("_cust","_dev") ;
   h1.definedone () ;
   declare hiter hi('h');
   declare hiter hh('h1');
   call missing(__cust,__dev);
end;
array t(999) $5;
n=0;
do until(last.cust);
	set have end=l;
	by cust;
	if first.cust then 
		do;
			if h.find(key:cust) = 0 then f1=1;
			else do while(hi.next()=0);
			if dev=__dev	then do; f2=1;leave;end;
			end;
			if sum(f1, f2)=. then do;c+1;uid =cats( 'UID', put(c,8. -l)); end;
		end;
	do rc1=h1.find(key:dev) by 0 while(rc1=0);
		rc=h.add(key:_cust,data:_cust,data: _dev,data:uid);
		if _cust ne cust then do;
		n+1;
		t(n)=_cust;
		end;
		rc1=h1.find_next();
	end;
end;
do i=1 to dim(t);
	if not missing(t(i)) then 
	do while(hh.next()=0);
	if t(i)=_cust then rc=h.add(key:_cust,data:_cust,data: _dev,data:uid);
	end;
end;
if l then h.output(dataset:'w');
run;

/*Final Want	*/
proc sort data=w out=want nodupkey;
by uid __cust __dev;
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Dec 2018 18:35:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-unique-identifier-for-multiple-columns-with-same-values/m-p/521236#M141402</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-12-13T18:35:15Z</dc:date>
    </item>
    <item>
      <title>Re: SAS: unique identifier for multiple columns with same values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-unique-identifier-for-multiple-columns-with-same-values/m-p/521273#M141409</link>
      <description>&lt;P&gt;I appreciate your devotion to solving this problem&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;. In my testing I try to "break" your code to help debug by adding/removing all kinds of customers and devices while knowing what to expect ahead of time. Your latest answer works for the test data, but it does not work for the previous example (removing Customer A Device 5).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I went back to the previous example (removing Customer A Device 5) that resulted in UID1 and UID2.&amp;nbsp; I then added a new customer (Y) that is linked to UID1 via Device 7 and also linked to UID2 via Device 5.&amp;nbsp; This should create a link among all records (all UID1) but again it creates extra records and assigns multiple UIDs.&amp;nbsp; N=13 records in ‘have’, N=18 records in ‘want’.&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;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
length cust dev $5;
input cust $ dev $;
datalines;
a 1
a 2
a 7
b 2
b 3
c 3
d 4
e 5
h 2
x 4
x 5
y 7
y 5
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Again, your help is much appreciated! I'm sure it is tough to make robust since the test data provided probably does not offer enough data to thoroughly validate.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Dec 2018 20:01:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-unique-identifier-for-multiple-columns-with-same-values/m-p/521273#M141409</guid>
      <dc:creator>kilo_foxtrot</dc:creator>
      <dc:date>2018-12-13T20:01:22Z</dc:date>
    </item>
    <item>
      <title>Re: SAS: unique identifier for multiple columns with same values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-unique-identifier-for-multiple-columns-with-same-values/m-p/521304#M141419</link>
      <description>&lt;P&gt;Hmm, i understand the bigger complexity now after staring at the example. Let me deal with simple piecemeal approach and respond.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Dec 2018 22:13:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-unique-identifier-for-multiple-columns-with-same-values/m-p/521304#M141419</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-12-13T22:13:03Z</dc:date>
    </item>
    <item>
      <title>Re: SAS: unique identifier for multiple columns with same values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-unique-identifier-for-multiple-columns-with-same-values/m-p/521305#M141420</link>
      <description>&lt;P&gt;I think this needs a kind of recursive approach, for which you will need to have the whole dataset in the hash.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Dec 2018 22:15:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-unique-identifier-for-multiple-columns-with-same-values/m-p/521305#M141420</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-12-13T22:15:43Z</dc:date>
    </item>
    <item>
      <title>Re: SAS: unique identifier for multiple columns with same values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-unique-identifier-for-multiple-columns-with-same-values/m-p/521312#M141426</link>
      <description>&lt;P&gt;&amp;nbsp;Absolutely right sir&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;.&amp;nbsp; The idea is in my mind, just the references/syntax causes my eyes more strain as the evening unfolds. Excellent observation!&lt;/P&gt;</description>
      <pubDate>Thu, 13 Dec 2018 22:36:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-unique-identifier-for-multiple-columns-with-same-values/m-p/521312#M141426</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-12-13T22:36:37Z</dc:date>
    </item>
    <item>
      <title>Re: SAS: unique identifier for multiple columns with same values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-unique-identifier-for-multiple-columns-with-same-values/m-p/521323#M141437</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/250583"&gt;@kilo_foxtrot&lt;/a&gt;&amp;nbsp; This is close to applying brute force. &lt;STRIKE&gt;Try and let me know.&lt;/STRIKE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
length cust dev $5;
input cust $ dev $;
datalines;
a 1
a 2
a 7
b 2
b 3
c 3
d 4
e 5
h 2
x 4
x 5
y 7
y 5
;
run;

dm log 'clear';
/*Intial look up*/
data _null_;
if _n_=1 then do;
length uid __dev __cust $5;
if 0 then set have(rename=(dev=_dev cust=_cust));
  declare hash H (multidata:'yes') ;
   h.definekey  ("__cust") ;
   h.definedata ("__cust","__dev","uid") ;
   h.definedone () ;
   declare hash H1 (dataset:'have(rename=(dev=_dev cust=_cust))', multidata:'yes') ;
   h1.definekey  ("_dev") ;
   h1.definedata ("_cust","_dev") ;
   h1.definedone () ;
   declare hiter hi('h');
   declare hiter hh('h1');
   call missing(__cust,__dev);
end;
array t(999) $5;
n=0;
do until(last.cust);
	set have end=l;
	by cust;
	if first.cust then 
		do;
			if h.find(key:cust) = 0 then f1=1;
			do while(hi.next()=0);
			if dev=__dev	then do; f2=1;leave;end;
			end;
			if sum(f1, f2)=. then do;c+1;uid =cats( 'UID', put(c,8. -l)); end;
		end;
	 do rc1=h1.find(key:dev) by 0 while(rc1=0);
		rc=h.add(key:_cust,data:_cust,data: _dev,data:uid);
		if _cust ne cust then do;
		n+1;
		t(n)=_cust;
		end;
		rc1=h1.find_next();
	end;
end;
do i=1 to dim(t);
	if not missing(t(i)) then 
	do while(hh.next()=0);
	if t(i)=_cust then rc=h.add(key:_cust,data:_cust,data: _dev,data:uid);
		do rc1=h1.find(key:_dev) by 0 while(rc1=0);
		rc=h.add(key:_cust,data:_cust,data: _dev,data:uid);
		rc1=h1.find_next();
		end;
	end;
end;
if l then h.output(dataset:'w');
run;

/*Final Want	*/
proc sort data=w out=want nodupkey;
by uid __cust __dev;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;There is still a glitch&lt;STRONG&gt;. Ignore this post&lt;/STRONG&gt; .Another garbage.hmm let me try again&lt;/P&gt;</description>
      <pubDate>Fri, 14 Dec 2018 05:31:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-unique-identifier-for-multiple-columns-with-same-values/m-p/521323#M141437</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-12-14T05:31:39Z</dc:date>
    </item>
    <item>
      <title>Re: SAS: unique identifier for multiple columns with same values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-unique-identifier-for-multiple-columns-with-same-values/m-p/521373#M141463</link>
      <description>&lt;P&gt;&lt;STRIKE&gt;HI&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/250583"&gt;@kilo_foxtrot&lt;/a&gt;&amp;nbsp; I spent sometime talking to my mate and researching online. It seems&amp;nbsp;networking problems often tend to have routes(paths) that can be infinite&amp;nbsp; as in our example, the more I try the link keeps going, on and on and on. Sure this can only go so far because the dataset isn't infinite but i think grouping one that is vast and expanded with duplicates needs a different approach.&lt;/STRIKE&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRIKE&gt;&amp;nbsp;&lt;/STRIKE&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRIKE&gt;Anyways, Can you provide me some logical/mathematical insight without referring to technology/functionality to guage how the loop stops from your experience/knowledge.&amp;nbsp;&lt;/STRIKE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Ignore all. Understood all but my brain didn't function well. My bad&lt;/P&gt;</description>
      <pubDate>Fri, 14 Dec 2018 14:50:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-unique-identifier-for-multiple-columns-with-same-values/m-p/521373#M141463</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-12-14T14:50:07Z</dc:date>
    </item>
    <item>
      <title>Re: SAS: unique identifier for multiple columns with same values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-unique-identifier-for-multiple-columns-with-same-values/m-p/521395#M141468</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*method 1:SQL*/
%macro getResult;
	%local i j NOBS1 NOBS2;
	proc sql noprint;
		create table test_left as
			select * 
			from test 
			;
		create table test_result as
			select *,'' as UID length=20
			from test_left
			where 1=2
			;
	quit;

	%let i=1;
	%do %until(%left(&amp;amp;NOBS1) eq 0);
		%let NOBS1=0;
		proc sql noprint;
			select count(*) into :NOBS1 from test_left; 
		quit;

		%if %left(&amp;amp;NOBS1) gt 0 %then %do;
			%let j=1;
			%do %until(%left(&amp;amp;NOBS2) eq 0);
				%if &amp;amp;j eq 1 %then %do;
					proc sql noprint;
						create table test_id as
							select distinct cust 
							from test_left(firstobs=1 obs=1)
							;
					quit;
				%end;
				%else %do;
					proc sql noprint;
						create table test_id as
							select distinct cust 
							from test_left
							where dev in (select distinct dev from test_temp)
							;
					quit;
				%end;
					proc sql noprint;
						create table test_temp as
							select * 
							from test_left 
							where cust in (select distinct cust from test_id)
							;
						create table test_left as
							select * 
							from test_left 
							where cust not in (select distinct cust from test_id)
							;
					quit;			

			
				%let NOBS2=0;
				proc sql noprint;
					select count(*) into :NOBS2 from test_temp; 
				quit;

				%if %left(&amp;amp;NOBS2) gt 0 %then %do;	
					proc sql noprint;
						insert into test_result
							select *,cats('UID',"%left(&amp;amp;i)") as UID length=20
							from test_temp
							;
					quit;
				%end;
				%let j=%eval(&amp;amp;j+1);
			%end;
		%end;
		%let i=%eval(&amp;amp;i+1);
	%end;
	proc sql noprint;
		drop table test_left;
		drop table test_temp;
		drop table test_id;
	quit;
%mend;
%getResult;

/*method 2*/
%macro getResult;
	%local i j NOBS1 NOBS2;
	data test_left;
		set test;
	run;
	data test_result;
		set test_left;
		attrib UID length=$20;
		stop;
	run;
	%let i=1;
	%do %until(%left(&amp;amp;NOBS1 eq 0));
		%let NOBS1=0;
		proc sql noprint;
			select count(*) into :NOBS1 from test_left; 
		quit;
		%if %left(&amp;amp;NOBS1) gt 0 %then %do;
			%let j=1;
			%do %until(%left(&amp;amp;NOBS2 eq 0));
				%if &amp;amp;j eq 1 %then %do;
					data test_id;
						set test_left(firstobs=1 obs=1);			
					run;
				%end;
				%else %do;
					proc sql noprint;
						create table test_id as
							select distinct cust 
							from test_left
							where dev in (select distinct dev from test_temp)
							;
					quit;
				%end;
				data  test_left test_temp;
					set test_left;
					Flag=0;
					do i=1 to ncount;
						set test_id(keep=cust rename=(cust=cust_id)) nobs=ncount point=i;
						if cust_id=cust then do;Flag=1;leave;end;
					end;
					if flag=1 then output test_temp;else output test_left;	
					drop flag cust_id;
				run;				
				%let NOBS2=0;
				proc sql noprint;
					select count(*) into :NOBS2 from test_temp; 
				quit;
				%if %left(&amp;amp;NOBS2) gt 0 %then %do;	
					data  temp;
						set test_temp;
						UID='UID'||"%left(&amp;amp;i)";
					run;
					proc append base=test_result data=temp force;
					run;
				%end;	
				%let j=%eval(&amp;amp;j+1);
			%end;
		%end;
		%let i=%eval(&amp;amp;i+1);
	%end;
	proc delete data=test_left;run;
	proc delete data=test_temp;run;
	proc delete data=test_id;run;
	proc delete data=temp;run;
%mend;
%getResult;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 14 Dec 2018 08:19:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-unique-identifier-for-multiple-columns-with-same-values/m-p/521395#M141468</guid>
      <dc:creator>learsaas</dc:creator>
      <dc:date>2018-12-14T08:19:34Z</dc:date>
    </item>
    <item>
      <title>Re: SAS: unique identifier for multiple columns with same values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-unique-identifier-for-multiple-columns-with-same-values/m-p/522047#M141678</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/250583"&gt;@kilo_foxtrot&lt;/a&gt;&amp;nbsp; Dec,17,2018 attempt&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
length cust dev $5;
input cust $ dev $;
datalines;
a 1
a 2
a 51
b 2
b 3
c 3
d 4
e 5
h 2
x 4
x 5
y 7
y 5
z 8
k 6
l 9
l 3
j 51
j 9
j 1
m 11
n 13
;
run;

proc sort data=have;
by cust dev;
run;
dm log 'clear';

data _null_;
if _n_=1 then do;
  if 0 then set have(rename=(dev=_dev cust=_cust));
  length __dev UID __cust $5;
	/*H initial full load*/
  dcl hash H (dataset:'have(rename=(dev=_dev cust=_cust))',multidata:'y') ;
   h.definekey  ("_dev") ;
   h.definedata ("_cust", "_dev") ;
   h.definedone () ;
   dcl hiter hh('h');
   	/*H1 Look up and load part by part load proceeding to our need*/
   dcl hash H1 (multidata:'y',ordered:'y') ;
   h1.definekey  ("__cust") ;
   h1.definedata ("__cust", "__dev","UID") ;
   h1.definedone () ;
   dcl hiter hh1('h1');
   call missing(__dev,__cust);
end;
array t(999) $5;
array j(999) $5;
do until(last.cust);
	set have end=l;
	by cust;
	if first.cust then 
	do;
		if  h1.find(key:cust)= 0 then f=1;
		if not f then do; c+1; uid= cats( 'UID', put(c,8. -l));end;
	end;
	if not f then 
	do;
		/*Look from dev to cust and collect cust residuals in array*/
			do rc1=h.find(key:dev) by 0 while(rc1=0);
				rc=h1.add(key:_cust,data:_cust,data:_dev,data:uid);
		/*collect cust residuals in array that's not part of cust but part of device*/
				if _cust ne cust then do;n+1;t(n)=_cust;end;
				rc1=h.find_next();
			end;
	end;
end;
n=0;
if not f then 
do;
	/*Residual look up-start with cust and iterate with dev*cust recursively until all check complete*/
	do until(sum(cmiss(of t(*)),cmiss(of j(*)))=dim(t)*2);
		do i=1 to dim(t);
			if not missing(t(i)) then 
	/*iterate the full load h using hh*/
				do while(hh.next()=0);
					if t(i)=_cust then
					do;
		/*Check if residual cust's* dev is not in part load hash,if not then fetch*/
						k=.;
						do while(hh1.next()=0);
						if __dev = _dev then do; k=1;leave;end;
						end;
						if not  k then do;n1+1;j(n1)=_dev;end;
						rc=h1.add(key:_cust,data:t(i),data:_dev,data:uid);
					end;	
				end;
		end;
		call missing(of t(*));n1=0;
		do i=1 to dim(j);
			if not missing(j(i)) then 
				do rc1=h.find(key:j(i)) by 0 while(rc1=0);
			/*Check if residual dev's *cust is not in part load hash,if not then fetch*/
					if h1.check(key:_cust) ne 0 then do;n+1;t(n)=_cust;end;
					rc=h1.add(key:_cust,data:_cust,data:_dev,data:uid);
					rc1=h.find_next();
				end;
		end;
		call missing(of j(*));n=0;
	end;
end;
if l then h1.output(dataset:'want');
run;

proc sort data=want out=final_want nodupkey ;
by uid __cust __dev ;
run;


&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 17 Dec 2018 22:19:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-unique-identifier-for-multiple-columns-with-same-values/m-p/522047#M141678</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-12-17T22:19:51Z</dc:date>
    </item>
  </channel>
</rss>

