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!
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;
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;
Brilliant! Thank you very much, it works perfectly 🙂
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.