How do I create a unique ID based on four patient variables

Accepted Solution Solved
Reply
New Contributor
Posts: 4
Accepted Solution

How do I create a unique ID based on four patient variables

Hi,

 

I am new to using SAS. I have a query about creating a unique ID for a group of patients that is based on a number of variables in SAS 9.4.

 

I have 276 episodes of care, in which the same patient may have presented multiple times. I have no unique ID for them and I would like to create one. The 276 episodes of care have been pulled out of 14,000 episodes in which there was a unique ID for those episodes but it is missing for the 276 episodes.

 

The variables I have to identify the patients are: surname, given initial, birth date and gender.

 

What I have done so far and where my problem is (code and screen shots below):

 

From the 276 episodes of care I got rid of the duplicate patients based on the above variables (there are 240 patients in the 276 episodes of care).

 

Then I created a unique ID for them and then merged the 240 patients back to the 276 episodes of care. However, when I do this, SAS recognises that the patients are the same on the newid variable, but it does not input the same value for the newid1 variable, which is the unique ID I have created (screen shot in attachment).

 

Note – I start at 9132 for the newid1 variable as I plan to merge data with original unique IDs back to the bigger dataset with 14,000 episodes of care in which there are 9131 unique patients.

 

Code:

proc sort data=missing_ID out=missing_ID1 nodupkey;

by surname given_initial gender birth_date;

run;

data missing_ID2;

set missing_ID1;

newid1+1;

newid=newid1+9132;

run;

 

proc sort data= missing_ID2;

by surname given_initial gender birth_date;

run;

 

proc sort data= missing_ID;

by surname given_initial gender birth_date;

run;

 

data all_missing_merged;

merge missing_ID missing_ID2;

by surname given_initial gender birth_date;

run;

 

Screen shot is in an attachment. 

 

Thanks in advance for our help!

 


Accepted Solutions
Solution
‎05-11-2016 05:43 AM
Respected Advisor
Posts: 4,804

Re: How do I create a unique ID based on four patient variables

You can do this operation in a single step:

 

proc sort data=missing_ID;
by surname given_initial gender birth_date;
run;

data all_missing;
set missing_ID;
by surname given_initial gender birth_date;
newid1 + first.birth_date;
newid=newid1+9132;
drop newid1;
run;
PG

View solution in original post


All Replies
Solution
‎05-11-2016 05:43 AM
Respected Advisor
Posts: 4,804

Re: How do I create a unique ID based on four patient variables

You can do this operation in a single step:

 

proc sort data=missing_ID;
by surname given_initial gender birth_date;
run;

data all_missing;
set missing_ID;
by surname given_initial gender birth_date;
newid1 + first.birth_date;
newid=newid1+9132;
drop newid1;
run;
PG
New Contributor
Posts: 4

Re: How do I create a unique ID based on four patient variables

Brilliant! Thank you very much, it works perfectly Smiley Happy

☑ This topic is solved.

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

Discussion stats
  • 2 replies
  • 322 views
  • 1 like
  • 2 in conversation