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

Hi all,

I have a question in regards to sequencing in SAS.  I have a large dataset of dates of birth that I would like to assign unique identifiers to, since they did not come with one.  If there are two cells in a row that have the same date of birth, they are the same person and should have the same unique ID. Below is an example of what I would like my dataset to look like:

DOBID
9/9/20001
9/9/20001
8/11/19932
7/7/19873
7/7/19873
7/7/19873
2/28/20014
2/28/20014
10/18/19675

I'm just not sure how to sequence correctly in SAS so if a date of birth is equal directly after another date of birth, that they are assigned the same unique ID.  And if the date of birth is different, then a new unique ID is assigned.  Thank you for help in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

The programming isn't difficult ... it might be as easy as:

data want;

  set have;

   by DOB notsorted;

   if first.DOB then ID + 1;

run;

Defining the problem is another story.  For example, do the DOB values have to be consecutive in the data for them to represent the same person?  (The sample solution assumes that they have to be consecutive.)  Do you have an additional variable you could use to make sure the matching DOB values are actually the same person?  It would be entirely possible for two consecutive people to have the same DOB.  Depending on what you mean by a "large" data set, it might be more or less likely that this will occur.

View solution in original post

5 REPLIES 5
Astounding
PROC Star

The programming isn't difficult ... it might be as easy as:

data want;

  set have;

   by DOB notsorted;

   if first.DOB then ID + 1;

run;

Defining the problem is another story.  For example, do the DOB values have to be consecutive in the data for them to represent the same person?  (The sample solution assumes that they have to be consecutive.)  Do you have an additional variable you could use to make sure the matching DOB values are actually the same person?  It would be entirely possible for two consecutive people to have the same DOB.  Depending on what you mean by a "large" data set, it might be more or less likely that this will occur.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Could also use proc rank; by dob;

brousseg
Calcite | Level 5

The DOB values do have to be consecutive in the data.  I also have gender that I could use to make sure that there aren't two random people back to back that happen to have the same DOB.

Astounding
PROC Star

In that case, you could use the program I posted with one change:

by GENDER DOB notsorted;

You would not need to sort your data first as long as consecutive matching records belong to the same person, and nonconsecutive records belong to different people.

brousseg
Calcite | Level 5

Thank you for your help, it is very much appreciated!

sas-innovate-2024.png

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.

 

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
  • 5 replies
  • 552 views
  • 3 likes
  • 3 in conversation