BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
LauraF1
Calcite | Level 5

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!

 

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

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

2 REPLIES 2
PGStats
Opal | Level 21

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
LauraF1
Calcite | Level 5

Brilliant! Thank you very much, it works perfectly 🙂

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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