<?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: creating random id's in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/creating-random-id-s/m-p/563247#M157875</link>
    <description>&lt;P&gt;Yes, they should&lt;/P&gt;</description>
    <pubDate>Mon, 03 Jun 2019 12:47:18 GMT</pubDate>
    <dc:creator>Anita_n</dc:creator>
    <dc:date>2019-06-03T12:47:18Z</dc:date>
    <item>
      <title>creating random id's</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-random-id-s/m-p/563245#M157873</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;am tring to create some random id in sas für about 1600 datasets. I have used most examples I search for but its not working.&lt;/P&gt;&lt;P&gt;I want something like a four integer id e.g. 1045&lt;/P&gt;&lt;P&gt;Can any&amp;nbsp; one help?&lt;/P&gt;</description>
      <pubDate>Mon, 03 Jun 2019 12:37:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-random-id-s/m-p/563245#M157873</guid>
      <dc:creator>Anita_n</dc:creator>
      <dc:date>2019-06-03T12:37:48Z</dc:date>
    </item>
    <item>
      <title>Re: creating random id's</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-random-id-s/m-p/563246#M157874</link>
      <description>&lt;P&gt;I assume that these IDs has to be unique? Should the ID's simply be in a single numeric variable or?&lt;/P&gt;</description>
      <pubDate>Mon, 03 Jun 2019 12:40:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-random-id-s/m-p/563246#M157874</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-06-03T12:40:38Z</dc:date>
    </item>
    <item>
      <title>Re: creating random id's</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-random-id-s/m-p/563247#M157875</link>
      <description>&lt;P&gt;Yes, they should&lt;/P&gt;</description>
      <pubDate>Mon, 03 Jun 2019 12:47:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-random-id-s/m-p/563247#M157875</guid>
      <dc:creator>Anita_n</dc:creator>
      <dc:date>2019-06-03T12:47:18Z</dc:date>
    </item>
    <item>
      <title>Re: creating random id's</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-random-id-s/m-p/563250#M157876</link>
      <description>&lt;P&gt;Try function UUIDGEN()&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Jun 2019 13:03:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-random-id-s/m-p/563250#M157876</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-06-03T13:03:52Z</dc:date>
    </item>
    <item>
      <title>Re: creating random id's</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-random-id-s/m-p/563251#M157877</link>
      <description>&lt;P&gt;Here is one way&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
    do id=1 to 9999;
        output;
    end;
run;

proc surveyselect data=test
   method=srs n=1600 out=want;
run;

proc datasets lib=work nolist;
    modify want;
        format id z4.;
run;quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 03 Jun 2019 13:07:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-random-id-s/m-p/563251#M157877</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-06-03T13:07:34Z</dc:date>
    </item>
    <item>
      <title>Re: creating random id's</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-random-id-s/m-p/563253#M157878</link>
      <description>&lt;P&gt;ok thanks,&lt;/P&gt;&lt;P&gt;let me try an see&lt;/P&gt;</description>
      <pubDate>Mon, 03 Jun 2019 13:28:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-random-id-s/m-p/563253#M157878</guid>
      <dc:creator>Anita_n</dc:creator>
      <dc:date>2019-06-03T13:28:58Z</dc:date>
    </item>
    <item>
      <title>Re: creating random id's</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-random-id-s/m-p/563283#M157890</link>
      <description>&lt;P&gt;Here's the long winded approach I usually use.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*This program demonstrates how to create a basic anonymized 
key for a unique identifier. Ensure you set the value in CALL
STREAMINIT()/RANDOM_SEED macro variable to ensure you can 
replicate the keys if needed*/

%let random_seed = 30;

*list of unique values;
proc sql; 
create table unique_list as
select distinct name
from sashelp.class;
quit;

*add random values;
data random_values;
set unique_list;
call streaminit(&amp;amp;random_seed.);
rand = rand('normal', 50, 10);
run;

*sort;
proc sort data=random_values;
by rand;
run;

*Assign ID to N, note this is a character format;
data ID_key_pair;
set random_values;
label = put(_n_, z5.);

fmtname = 'anon_fmt';
type='C';
start=name;
run;

*Create a format;
proc format cntlin=id_key_pair;
run;

*Create dataset with anonymized IDs;
data want;
set sashelp.class;
RandomID = put(name, $anon_fmt.);
*drop name;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/168930"&gt;@Anita_n&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello all,&lt;/P&gt;
&lt;P&gt;am tring to create some random id in sas für about 1600 datasets. I have used most examples I search for but its not working.&lt;/P&gt;
&lt;P&gt;I want something like a four integer id e.g. 1045&lt;/P&gt;
&lt;P&gt;Can any&amp;nbsp; one help?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Jun 2019 15:04:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-random-id-s/m-p/563283#M157890</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-06-03T15:04:52Z</dc:date>
    </item>
    <item>
      <title>Re: creating random id's</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-random-id-s/m-p/563337#M157915</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/168930"&gt;@Anita_n&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You need a 4-digit ID, but I wonder why you want it created as a random number in addition to being unique. How do you plan to use the ID, since a simple sequence number will not work?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But if this is essential, you could create a random number, sort the data set on the random number, so the observarions are shuffled like a card deck, and then replace the random number with a sequence number as a 4-digit ID.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;* Test data set;
data test;
    do orig_sequence = 1 to 9999;
        output;
    end;
run;


%macro AddRandomID(ds, dsout);
	* Add a random bumber;
	data w1; set &amp;amp;ds;
		random_number = ranuni(5);
	run;

	* Sort by random number;
	proc sort data=w1; by random_number;
	run;

	* Replace random number with sequence number as ID variable;
	data &amp;amp;dsout; set w1(drop=random_number);
		format ID z4.;
		ID = _N_;
	run;

	* Sort back to original sequence to demonstrate the "randomness";
	proc sort data=&amp;amp;dsout; by orig_sequence;
	run;
%mend;
%AddRandomID(test,test_id);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 03 Jun 2019 17:06:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-random-id-s/m-p/563337#M157915</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2019-06-03T17:06:17Z</dc:date>
    </item>
  </channel>
</rss>

