SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

Random id for same mother

Accepted Solution Solved
Reply
Contributor
Posts: 40
Accepted Solution

Random id for same mother

Hello,

 

I am trying to assign a random id to mothers in a dataset for 4 years. Of course there are many mothers who give birth more than once in this dataset so I will like to use the same random id if that is the case. I have close to 200,000 records and a key using last name, first name and DOB of the mothers.

 

thanks!


Accepted Solutions
Solution
‎02-29-2016 09:25 AM
Respected Advisor
Posts: 4,932

Re: Random id for same mother

Or, if you just want large non repeating numbers as ids :

 

proc sort data=mothers; by lastName firstName dob; run;

data mothersId;
call streaminit(7566);
retain id;
set mothers; by lastName firstName dob;
if first.dob then id = int(1e12*rand("UNIFORM"));
format id z12.0;
run;
PG

View solution in original post


All Replies
Contributor
Posts: 40

Random id for same mother

Hello,

 

I am trying to assign a random id to mothers in a dataset for 4 years. Of course there are many mothers who give birth more than once in this dataset so I will like to use the same random id if that is the case. I have close to 200,000 records and a key using last name, first name and DOB of the mothers.

 

thanks!

Super User
Posts: 5,437

Re: Random id for same mother

What will be the use of the random id?
Data never sleeps
PROC Star
Posts: 1,167

Re: Random id for same mother

People frequently use UUIDs for this. Check out the UUIDGEN function.

 

Tom

Respected Advisor
Posts: 4,932

Re: Random id for same mother

To get random ids going from 1 to the number of distinct mothers, do:

 

proc sort data=mothers; by lastName firstName dob; run;

data mothers2;
call streaminit(7568);
retain id;
set mothers; by lastName firstName dob;
if first.dob then id = rand("UNIFORM");
run;

proc rank data=mothers2 out=mothersId ties=dense;
var id;
run;

(untested)

PG
Solution
‎02-29-2016 09:25 AM
Respected Advisor
Posts: 4,932

Re: Random id for same mother

Or, if you just want large non repeating numbers as ids :

 

proc sort data=mothers; by lastName firstName dob; run;

data mothersId;
call streaminit(7566);
retain id;
set mothers; by lastName firstName dob;
if first.dob then id = int(1e12*rand("UNIFORM"));
format id z12.0;
run;
PG
Contributor
Posts: 40

Re: Random id for same mother

thank you! this works perfectly

Super User
Posts: 10,044

Re: Random id for same mother

Hash Table

 

data have;
input first $ last $ dob : date9.;
format dob date9.;
cards;
a b 03jun1991
b c 09jan1980
b c 09jan1980
a b 03jun1991
;
run;
data want;
 if _n_=1 then do;
  if 0 then set have;
  declare hash h();
  h.definekey('first','last','dob');
  h.definedata('id');
  h.definedone();
 end;
 set have;
 rc=h.find();
 if rc ne 0 then do;n+1;id=n;h.add();end;
 drop rc n;
run;
Super User
Posts: 5,437

Re: Random id for same mother

Not knowing the use case, but perhaps hashing the concatenated business key values could be one solution.
The id values will distributed, it's quite safe if privacy is required and it's simple to use: given the same input always the same hash is produced. Check out the md5() function.
Data never sleeps
Super User
Posts: 19,861

Re: Random id for same mother

Hashing isn't a good idea...

 

New York Taxi Open Data - Reversed Engineered

http://www.theguardian.com/technology/2014/jun/27/new-york-taxi-details-anonymised-data-researchers-...

 

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 9 replies
  • 476 views
  • 0 likes
  • 6 in conversation