<?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: Building a lookup table to avoid duplicates in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Building-a-lookup-table-to-avoid-duplicates/m-p/338976#M77286</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I wouldn't do it quite like that.&amp;nbsp; Let's say your 20 datasets (named DS1, DS2, ... DS20)&amp;nbsp; have N1, N2, ... N20 observations, totalling to 2015632 observations:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then generate 2,015,632 id's in sequence, and re-order them randomly (you could get this number using proc sql drawing from dictionary.tables, but for now, just look at your datasets and calculate the total observation count):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Step 1: Generate needed id's and order randomly:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let n_all=2015632;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data v_ranids /view=v_ranids;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; do id=1 to &amp;amp;n_all;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rn=rand('uniform');&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;proc sort data=v_ranids out=ranids (keep=id);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; by rn;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Step 2: Now define a macro which will later&amp;nbsp;be applied in sequence to each dataset,&amp;nbsp;&amp;nbsp; DS1,&amp;nbsp; DS2, ....&amp;nbsp; It will support taking the first N1 id's in ranid for DS1, the next N2 for DS2, etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro ranid(dsname=);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; data new_&amp;amp;dsname (drop=next_frstobs);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; merge &amp;amp;dsname (in=inkeep)&amp;nbsp; ranid (firstobs=&amp;amp;frstob);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; if inkeep=0 then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; next_firstobs=&amp;amp;frstob+_n_-1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; call symput("frstob",cats(next_frstobs));&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;stop;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;%mend ranid;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Step 3.1 through 3.20:&amp;nbsp;Now just run the macro once per dataset, making sure you set the macrovar FRSTOB to 1 before the first macro call.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let frstob=1;&lt;/P&gt;
&lt;P&gt;%ranid(ds1);&lt;/P&gt;
&lt;P&gt;%ranid(ds2);&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;%ranid(ds20);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note: If your program stops after, say dataset 6, then you want to run the macros starting with data set 7 ... BUT ... you have to set the macrovar FRSTOB to&amp;nbsp;&amp;nbsp;&amp;nbsp; N1+N2+...+N6 + 1.&lt;/P&gt;</description>
    <pubDate>Tue, 07 Mar 2017 20:32:47 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2017-03-07T20:32:47Z</dc:date>
    <item>
      <title>Building a lookup table to avoid duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Building-a-lookup-table-to-avoid-duplicates/m-p/338958#M77279</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have 20 different files (over 100 thousand records each), in each file, I want to generate a randomly generated number ID, and make sure that there are no duplicates across the years. My solution is to generate the random numbers for first file, then put those in a master list, then generate random numbers&amp;nbsp;for the second&amp;nbsp;file, check the master list to ensure those numbers don't already exist, if they do, replace,&amp;nbsp;and add&amp;nbsp;all the random numbers to the master&amp;nbsp;list, then&amp;nbsp;generate random&amp;nbsp;numbers for the 3rd file and so on...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there an easy way of programming this? Are there procedures that are meant&amp;nbsp;for this kind of process?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2017 19:45:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Building-a-lookup-table-to-avoid-duplicates/m-p/338958#M77279</guid>
      <dc:creator>Shirin</dc:creator>
      <dc:date>2017-03-07T19:45:14Z</dc:date>
    </item>
    <item>
      <title>Re: Building a lookup table to avoid duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Building-a-lookup-table-to-avoid-duplicates/m-p/338968#M77282</link>
      <description>&lt;P&gt;For an ID variable, isn't a sequential number just as random as anything else you might assign?&amp;nbsp; Just assign values of 1 through 100,000 for the first data set, 100,001 through 200,000 for the second data set, etc.&amp;nbsp; Do you have some requirements down the road that makes these ID values any less "random" than a more complex approach?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you need to select observations randomly later, PROC SURVEYSELECT can do that without requiring a randomly assigned ID variable.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2017 20:08:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Building-a-lookup-table-to-avoid-duplicates/m-p/338968#M77282</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-03-07T20:08:28Z</dc:date>
    </item>
    <item>
      <title>Re: Building a lookup table to avoid duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Building-a-lookup-table-to-avoid-duplicates/m-p/338969#M77283</link>
      <description>&lt;P&gt;Unfortunately I can't use sequential IDs, it has to be randomly generated numbers.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2017 20:10:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Building-a-lookup-table-to-avoid-duplicates/m-p/338969#M77283</guid>
      <dc:creator>Shirin</dc:creator>
      <dc:date>2017-03-07T20:10:28Z</dc:date>
    </item>
    <item>
      <title>Re: Building a lookup table to avoid duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Building-a-lookup-table-to-avoid-duplicates/m-p/338973#M77284</link>
      <description>&lt;P&gt;It sounds like you may want to look into something like a &lt;A href="https://en.wikipedia.org/wiki/Universally_unique_identifier" target="_self"&gt;GUID/UUID&lt;/A&gt;. &amp;nbsp;I don't think SAS has that functionality built in, but I'm sure you could create some modular code to do it. &amp;nbsp;Or very likely someone already has if you start digging around.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2017 20:22:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Building-a-lookup-table-to-avoid-duplicates/m-p/338973#M77284</guid>
      <dc:creator>Sven111</dc:creator>
      <dc:date>2017-03-07T20:22:03Z</dc:date>
    </item>
    <item>
      <title>Re: Building a lookup table to avoid duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Building-a-lookup-table-to-avoid-duplicates/m-p/338974#M77285</link>
      <description>&lt;P&gt;Actually, I just read my own link a bit closer, and it should actually be fairly simple to create a FCMP or Macro function that creates a v3 or v5 UUID/GUID since they primarily rely on MD5/SHA-1, both of which are already existing functions in SAS.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2017 20:28:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Building-a-lookup-table-to-avoid-duplicates/m-p/338974#M77285</guid>
      <dc:creator>Sven111</dc:creator>
      <dc:date>2017-03-07T20:28:37Z</dc:date>
    </item>
    <item>
      <title>Re: Building a lookup table to avoid duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Building-a-lookup-table-to-avoid-duplicates/m-p/338976#M77286</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I wouldn't do it quite like that.&amp;nbsp; Let's say your 20 datasets (named DS1, DS2, ... DS20)&amp;nbsp; have N1, N2, ... N20 observations, totalling to 2015632 observations:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then generate 2,015,632 id's in sequence, and re-order them randomly (you could get this number using proc sql drawing from dictionary.tables, but for now, just look at your datasets and calculate the total observation count):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Step 1: Generate needed id's and order randomly:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let n_all=2015632;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data v_ranids /view=v_ranids;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; do id=1 to &amp;amp;n_all;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rn=rand('uniform');&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;proc sort data=v_ranids out=ranids (keep=id);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; by rn;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Step 2: Now define a macro which will later&amp;nbsp;be applied in sequence to each dataset,&amp;nbsp;&amp;nbsp; DS1,&amp;nbsp; DS2, ....&amp;nbsp; It will support taking the first N1 id's in ranid for DS1, the next N2 for DS2, etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro ranid(dsname=);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; data new_&amp;amp;dsname (drop=next_frstobs);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; merge &amp;amp;dsname (in=inkeep)&amp;nbsp; ranid (firstobs=&amp;amp;frstob);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; if inkeep=0 then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; next_firstobs=&amp;amp;frstob+_n_-1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; call symput("frstob",cats(next_frstobs));&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;stop;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;%mend ranid;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Step 3.1 through 3.20:&amp;nbsp;Now just run the macro once per dataset, making sure you set the macrovar FRSTOB to 1 before the first macro call.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let frstob=1;&lt;/P&gt;
&lt;P&gt;%ranid(ds1);&lt;/P&gt;
&lt;P&gt;%ranid(ds2);&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;%ranid(ds20);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note: If your program stops after, say dataset 6, then you want to run the macros starting with data set 7 ... BUT ... you have to set the macrovar FRSTOB to&amp;nbsp;&amp;nbsp;&amp;nbsp; N1+N2+...+N6 + 1.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2017 20:32:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Building-a-lookup-table-to-avoid-duplicates/m-p/338976#M77286</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-03-07T20:32:47Z</dc:date>
    </item>
    <item>
      <title>Re: Building a lookup table to avoid duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Building-a-lookup-table-to-avoid-duplicates/m-p/338984#M77291</link>
      <description>&lt;P&gt;Assign the sequential and add a random number. Sort by the random number and drop the random number. Voila, the "sequential" values are now "random" numbers.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Maybe use a Z12. format to further&amp;nbsp;"disquise" the numbers.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2017 20:47:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Building-a-lookup-table-to-avoid-duplicates/m-p/338984#M77291</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-03-07T20:47:46Z</dc:date>
    </item>
    <item>
      <title>Re: Building a lookup table to avoid duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Building-a-lookup-table-to-avoid-duplicates/m-p/338988#M77294</link>
      <description>&lt;P&gt;I think the following would meet your requirements:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%macro assign(file);
  data &amp;amp;file;
    set &amp;amp;file end=eof nobs=nobs;
    if _n_ eq 1 then call streaminit(123);
    do _n_=1 to &amp;amp;i.;
      id=rand("uniform");
    end;
    id=rand("uniform");
    if eof then do;
      call symput('i',&amp;amp;i+nobs);
    end;
  run;
%mend assign;
%let i=1;
%assign(have1);
%assign(have2);
%assign(have3);
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2017 20:52:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Building-a-lookup-table-to-avoid-duplicates/m-p/338988#M77294</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-03-07T20:52:13Z</dc:date>
    </item>
    <item>
      <title>Re: Building a lookup table to avoid duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Building-a-lookup-table-to-avoid-duplicates/m-p/339005#M77301</link>
      <description>&lt;P&gt;art297, this is simple and beautiful, but does this ensure the uniqueness of my IDs?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I actually don't want to generate these IDs for all records in each dataset, but for those where ID_old is missing. And this is what I'm using for creating the new ID.&lt;/P&gt;
&lt;P&gt;ID_new = put (int (ranuni (7657) * 1e10) + 1 , z10.)&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2017 21:12:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Building-a-lookup-table-to-avoid-duplicates/m-p/339005#M77301</guid>
      <dc:creator>Shirin</dc:creator>
      <dc:date>2017-03-07T21:12:13Z</dc:date>
    </item>
    <item>
      <title>Re: Building a lookup table to avoid duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Building-a-lookup-table-to-avoid-duplicates/m-p/339009#M77304</link>
      <description>&lt;P&gt;It would only assure the assignment of unique IDs if you were using it to assign new IDs for all of your records across all of your files. Since you want to keep preexisting IDs, no, it wouldn't work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2017 21:17:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Building-a-lookup-table-to-avoid-duplicates/m-p/339009#M77304</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-03-07T21:17:15Z</dc:date>
    </item>
    <item>
      <title>Re: Building a lookup table to avoid duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Building-a-lookup-table-to-avoid-duplicates/m-p/339012#M77306</link>
      <description>&lt;P&gt;I could maybe separate those rows so that I assign IDs for all records... Unfortunately, I still don't understand how it'd assure IDs would be unique tho...&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2017 21:23:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Building-a-lookup-table-to-avoid-duplicates/m-p/339012#M77306</guid>
      <dc:creator>Shirin</dc:creator>
      <dc:date>2017-03-07T21:23:03Z</dc:date>
    </item>
    <item>
      <title>Re: Building a lookup table to avoid duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Building-a-lookup-table-to-avoid-duplicates/m-p/339018#M77308</link>
      <description>&lt;P&gt;Are you sure that you don't have any duplicate IDs across your existing files? The method I proposed would ensure the assignment of unique new IDs for every record. The logic is that it is using the same seed, but starting from the place where it left off with the previous file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are sure that you have unique IDs, you could use proc sql to identify the maximum id across all of your files, then build the logic into the code to only assign IDs that are greater than that value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2017 21:30:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Building-a-lookup-table-to-avoid-duplicates/m-p/339018#M77308</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-03-07T21:30:43Z</dc:date>
    </item>
    <item>
      <title>Re: Building a lookup table to avoid duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Building-a-lookup-table-to-avoid-duplicates/m-p/339020#M77309</link>
      <description>&lt;P&gt;art297, yes I believe this could work.&lt;/P&gt;
&lt;P&gt;All the rows I want to assign this ID to, have a bunch of blanks, some missing variables and some not missing, but I want them to have all different IDs.&lt;/P&gt;
&lt;P&gt;Is there a way to keep my format of put (int (ranuni (7657) * 1e10) + 1 , z10.)?&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2017 21:35:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Building-a-lookup-table-to-avoid-duplicates/m-p/339020#M77309</guid>
      <dc:creator>Shirin</dc:creator>
      <dc:date>2017-03-07T21:35:49Z</dc:date>
    </item>
    <item>
      <title>Re: Building a lookup table to avoid duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Building-a-lookup-table-to-avoid-duplicates/m-p/339044#M77324</link>
      <description>&lt;P&gt;May want to consider Rand('uniform') instead of ranuni.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And you just added an additional constraint missed in the original post: cannot be the same as any of the existing id values. That should have been explicitly stated up front.&lt;/P&gt;
&lt;P&gt;How many missing values are there? Are these id's actually numeric or numeral valued character? What is the largest existing value?&lt;/P&gt;
&lt;P&gt;It may be sufficient to increment past the largest existing.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2017 22:44:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Building-a-lookup-table-to-avoid-duplicates/m-p/339044#M77324</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-03-07T22:44:01Z</dc:date>
    </item>
    <item>
      <title>Re: Building a lookup table to avoid duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Building-a-lookup-table-to-avoid-duplicates/m-p/339050#M77326</link>
      <description>&lt;P&gt;I didn't add in a check and balance for existing IDs, but the following uses your format on a test case of 20 files where each file has 100,000 records. It also does a test at the end to see if any duplicate IDs were created:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%macro buildem;
  %do i=1 %to 20;
    data have&amp;amp;i.;
      do x=1 to 100000;
        output;
      end;
    run;
  %end;
%mend buildem;
%buildem

%global i;
%macro assignem(file);
  data &amp;amp;file;
    set &amp;amp;file end=eof nobs=nobs;
    if _n_ eq 1 then do;
      do _n_=1 to &amp;amp;i.;
        id=put(1+int(1e10*ranuni(7657)),z10.) ;
      end;
    end;
    id=put(1+int(1e10*ranuni(7657)),z10.) ;
    if eof then do;
      call symput('i',&amp;amp;i+nobs);
    end;
  run;
%mend assignem;
%let i=1;
%assignem(have1)
%assignem(have2)
%assignem(have3)
%assignem(have4)
%assignem(have5)
%assignem(have6)
%assignem(have7)
%assignem(have8)
%assignem(have9)
%assignem(have10)
%assignem(have11)
%assignem(have12)
%assignem(have13)
%assignem(have14)
%assignem(have15)
%assignem(have16)
%assignem(have17)
%assignem(have18)
%assignem(have19)
%assignem(have20)

data all;
  set have:;
run;

proc sort data=all nodupkey;
  by id;
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2017 23:24:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Building-a-lookup-table-to-avoid-duplicates/m-p/339050#M77326</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-03-07T23:24:18Z</dc:date>
    </item>
    <item>
      <title>Re: Building a lookup table to avoid duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Building-a-lookup-table-to-avoid-duplicates/m-p/339085#M77336</link>
      <description>&lt;PRE&gt;
data have;
do i=1 to 100;
 id=uuidgen();
 output;
end;
run;
proc print noobs;run;


&lt;/PRE&gt;</description>
      <pubDate>Wed, 08 Mar 2017 03:12:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Building-a-lookup-table-to-avoid-duplicates/m-p/339085#M77336</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-03-08T03:12:17Z</dc:date>
    </item>
  </channel>
</rss>

