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

Hi,

I have data just like below

 

Namedob
alexis1-Jan-00
alexander3-Aug-89
alexa2-Mar-90
alex3-Aug-89
alex2-Mar-90
alex1-Jan-00
alex1-Jan-00
alex7-Sep-01

 

and I wanto to give them ID like this

 

Namedob ID 
alexis1-Jan-00                 1
alexander3-Aug-89                 2
alexa2-Mar-90                 3
alex3-Aug-89                 4
alex2-Mar-90                 5
alex1-Jan-00                 6
alex1-Jan-00                 6
alex7-Sep-01                 7

 

Please help

 

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

 

data want;

set have;

by name dob notsorted;

if first.dob then id+1;

run;

 

View solution in original post

5 REPLIES 5
r_behata
Barite | Level 11
data want; 
Set have; 
ID=_n_;
Run;
icecubescb
Calcite | Level 5

hi behata,

if I want same ID for same name and DOB, I can't use _n_.

do you have any idea?

 

Thanks

novinosrin
Tourmaline | Level 20

 

data want;

set have;

by name dob notsorted;

if first.dob then id+1;

run;

 

icecubescb
Calcite | Level 5
novinosrin...
Thank you
Reeza
Super User

@icecubescb please mark @novinosrin solution as the correct answer if it answers your question. 

 

I would consider if NOTSORTED is good usage in this case but otherwise is pretty much the standard response. 

 

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 2765 views
  • 0 likes
  • 4 in conversation