<?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: Giving Unique Number in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Giving-Unique-Number/m-p/56214#M11999</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Still not understand what is your mean totally.&lt;/P&gt;&lt;P&gt;How about:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;data test;
input pan1 pan2 pan3 add1 ;
cards;
1 2 3 4
5 6 7 8
. . . .
1 2 7 8
1 5 9 12
13 14 15 16
12 18 19 .
;
run;

data want(keep=pan1 pan2 pan3 add1 household);
 set test;
 retain first;
 count+1;
 _count=0;
 do i=1 to _nobs;
&amp;nbsp; set test(rename=(pan1=_pan1 pan2=_pan2 pan3=_pan3 add1=_add1)) nobs=_nobs point=i;
&amp;nbsp; _count+1;
&amp;nbsp; if count ne _count and
&amp;nbsp;&amp;nbsp; ((pan1=_pan1 and not missing(_pan1))&amp;nbsp; or&amp;nbsp; (pan1=_pan2 and not missing(_pan2))&amp;nbsp; or (pan1=_pan3 and not missing(_pan3)) or (pan1=_add1 and not missing(_add1)) or 
&amp;nbsp;&amp;nbsp;&amp;nbsp; (pan2=_pan1 and not missing(_pan1))&amp;nbsp; or&amp;nbsp; (pan2=_pan2 and not missing(_pan2))&amp;nbsp; or (pan2=_pan3 and not missing(_pan3)) or (pan2=_add1 and not missing(_add1)) or 
&amp;nbsp;&amp;nbsp;&amp;nbsp; (pan3=_pan1 and not missing(_pan1))&amp;nbsp; or&amp;nbsp; (pan3=_pan2 and not missing(_pan2))&amp;nbsp; or (pan3=_pan3 and not missing(_pan3)) or (pan3=_add1 and not missing(_add1)) or 
&amp;nbsp;&amp;nbsp;&amp;nbsp; (add1=_pan1 and not missing(_pan1))&amp;nbsp; or&amp;nbsp; (add1=_pan2 and not missing(_pan2))&amp;nbsp; or (add1=_pan3 and not missing(_pan3)) or (add1=_add1 and not missing(_add1))&amp;nbsp; )
&amp;nbsp;&amp;nbsp;&amp;nbsp; then do; _n+1;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if _n eq 1 then do;
&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;&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; n+1; first=n;
&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;&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; household=n;
&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else household=first;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; found=1;leave;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;
 end;
 if not found then do; n+1; household=n; end;
run;

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: xia keshan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 30 Aug 2011 07:26:03 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2011-08-30T07:26:03Z</dc:date>
    <item>
      <title>Giving Unique Number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Giving-Unique-Number/m-p/56210#M11995</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Grouping and Giving one id&lt;BR /&gt;Hi i am having pan1,pan2,pan3 and add1&lt;BR /&gt;now i want to generate household id on that&lt;/P&gt;&lt;P&gt;data test;&lt;BR /&gt;input pan1 pan2 pan3 add1&lt;BR /&gt;cards;&lt;BR /&gt;1 2 3 4&lt;BR /&gt;5 6 7 8&lt;BR /&gt;. . . .&lt;BR /&gt;1 2 7 8&lt;BR /&gt;1 5 9 12&lt;BR /&gt;13 14 15 16&lt;BR /&gt;12 18 19 .&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;Here i want to create one unique number as Household id&lt;BR /&gt;first it should check the pan1 if any of the pan are in pan2 or pan3 or add1 it should give one&lt;BR /&gt;household id like versa pan2 should check the observations matching in pan1 or pan3 or add1&lt;BR /&gt;and pan3 and add1 to do the same like pan1 and pan2..&lt;BR /&gt;my final createria is to get one number unique if any of the pan1,pan2,pan3 and add1 obs matching&lt;BR /&gt;any where and i should generate one new number if all the observations are blank.&lt;BR /&gt;These is the process of creating household in Dataflux i am doing this in baase sas.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;output:&lt;BR /&gt;pan1 pan2 pan3 add1 Household&lt;BR /&gt;1 2 3 4&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;5 6 7 8&amp;nbsp; 1&lt;BR /&gt;. . . .&amp;nbsp; 2&lt;BR /&gt;1 2 7 8&amp;nbsp; 1&lt;BR /&gt;1 5 9 12 1 &lt;BR /&gt;13 14 15 16 3&lt;BR /&gt;12 18 19 . 1&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 29 Aug 2011 12:27:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Giving-Unique-Number/m-p/56210#M11995</guid>
      <dc:creator>sas_Forum</dc:creator>
      <dc:date>2011-08-29T12:27:07Z</dc:date>
    </item>
    <item>
      <title>Giving Unique Number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Giving-Unique-Number/m-p/56211#M11996</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You've posted this twice but haven't provided enough information for one to understand what you are trying to do.&amp;nbsp; You seem to want to increase Household by 1 each time something does or doesn't happen, but I wasn't able to understand what that event might be.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, you will have to clearly indicate if your actual data are just going to be numbers, like in your example and, if so, how large those numbers can be.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 29 Aug 2011 12:33:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Giving-Unique-Number/m-p/56211#M11996</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2011-08-29T12:33:19Z</dc:date>
    </item>
    <item>
      <title>Giving Unique Number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Giving-Unique-Number/m-p/56212#M11997</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; I want the Household id for the if&amp;nbsp; there is a observation 123 in pan1 and if this observations again accor in pan2 at any place and if in pan3 and add1 then these all should get one Household id not only that &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;pan1 pan2 pan3 add1&lt;/P&gt;&lt;P&gt;123&amp;nbsp;&amp;nbsp; 456&amp;nbsp;&amp;nbsp; 789 345&lt;/P&gt;&lt;P&gt;567 123&amp;nbsp; 098 067&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In this example if 123 is repeating on pan1 and pan2 then these two get one H_id not only that the number corresponding to &lt;/P&gt;&lt;P&gt;123 if occuring any where like(456 789 345 in obs1 and 567 098 067 in obs 2) like that they should &lt;/P&gt;&lt;P&gt;get same H_id...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 29 Aug 2011 12:46:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Giving-Unique-Number/m-p/56212#M11997</guid>
      <dc:creator>sas_Forum</dc:creator>
      <dc:date>2011-08-29T12:46:46Z</dc:date>
    </item>
    <item>
      <title>Giving Unique Number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Giving-Unique-Number/m-p/56213#M11998</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It sounds like you want to split your ids into connected subgraphs.&amp;nbsp; If you have SAS/OR licensed I have had success using PROC NETDRAW to do this.&amp;nbsp; Otherwise you can code your own logic.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would start by converting your data from the current four variables to two variables and populate it with pairs of values from your four variables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data relations;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set test;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array x pan1-pan3 add1 ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do i=1 to dim(x)-1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do j=i+1 to dim(x);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; id1=x(i); id2=x(j); output;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; id1=x(j); id2=x(i); output;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; keep id1 id2 ;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sort data=relations nodupkey;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by id1 id2;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can grow your own subnets by looping and adding in all of the connected ids from the current list until the current subnet stops growing.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 29 Aug 2011 17:32:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Giving-Unique-Number/m-p/56213#M11998</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2011-08-29T17:32:07Z</dc:date>
    </item>
    <item>
      <title>Re: Giving Unique Number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Giving-Unique-Number/m-p/56214#M11999</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Still not understand what is your mean totally.&lt;/P&gt;&lt;P&gt;How about:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;data test;
input pan1 pan2 pan3 add1 ;
cards;
1 2 3 4
5 6 7 8
. . . .
1 2 7 8
1 5 9 12
13 14 15 16
12 18 19 .
;
run;

data want(keep=pan1 pan2 pan3 add1 household);
 set test;
 retain first;
 count+1;
 _count=0;
 do i=1 to _nobs;
&amp;nbsp; set test(rename=(pan1=_pan1 pan2=_pan2 pan3=_pan3 add1=_add1)) nobs=_nobs point=i;
&amp;nbsp; _count+1;
&amp;nbsp; if count ne _count and
&amp;nbsp;&amp;nbsp; ((pan1=_pan1 and not missing(_pan1))&amp;nbsp; or&amp;nbsp; (pan1=_pan2 and not missing(_pan2))&amp;nbsp; or (pan1=_pan3 and not missing(_pan3)) or (pan1=_add1 and not missing(_add1)) or 
&amp;nbsp;&amp;nbsp;&amp;nbsp; (pan2=_pan1 and not missing(_pan1))&amp;nbsp; or&amp;nbsp; (pan2=_pan2 and not missing(_pan2))&amp;nbsp; or (pan2=_pan3 and not missing(_pan3)) or (pan2=_add1 and not missing(_add1)) or 
&amp;nbsp;&amp;nbsp;&amp;nbsp; (pan3=_pan1 and not missing(_pan1))&amp;nbsp; or&amp;nbsp; (pan3=_pan2 and not missing(_pan2))&amp;nbsp; or (pan3=_pan3 and not missing(_pan3)) or (pan3=_add1 and not missing(_add1)) or 
&amp;nbsp;&amp;nbsp;&amp;nbsp; (add1=_pan1 and not missing(_pan1))&amp;nbsp; or&amp;nbsp; (add1=_pan2 and not missing(_pan2))&amp;nbsp; or (add1=_pan3 and not missing(_pan3)) or (add1=_add1 and not missing(_add1))&amp;nbsp; )
&amp;nbsp;&amp;nbsp;&amp;nbsp; then do; _n+1;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if _n eq 1 then do;
&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;&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; n+1; first=n;
&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;&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; household=n;
&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else household=first;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; found=1;leave;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;
 end;
 if not found then do; n+1; household=n; end;
run;

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: xia keshan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 30 Aug 2011 07:26:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Giving-Unique-Number/m-p/56214#M11999</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-08-30T07:26:03Z</dc:date>
    </item>
  </channel>
</rss>

