Sequencing Question

Accepted Solution Solved
Reply
New Contributor
Posts: 4
Accepted Solution

Sequencing Question

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.


Accepted Solutions
Solution
‎04-07-2014 11:06 AM
Super User
Posts: 5,498

Re: Sequencing Question

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


All Replies
Solution
‎04-07-2014 11:06 AM
Super User
Posts: 5,498

Re: Sequencing Question

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.

Super User
Super User
Posts: 7,942

Re: Sequencing Question

Posted in reply to Astounding

Could also use proc rank; by dob;

New Contributor
Posts: 4

Re: Sequencing Question

Posted in reply to Astounding

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.

Super User
Posts: 5,498

Re: Sequencing Question

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.

New Contributor
Posts: 4

Re: Sequencing Question

Posted in reply to Astounding

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

🔒 This topic is solved and locked.

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

Discussion stats
  • 5 replies
  • 221 views
  • 3 likes
  • 3 in conversation