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!
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;
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!
People frequently use UUIDs for this. Check out the UUIDGEN function.
Tom
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)
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;
thank you! this works perfectly
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;
Hashing isn't a good idea...
New York Taxi Open Data - Reversed Engineered
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.