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. 

 

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 2092 views
  • 0 likes
  • 4 in conversation