DATA Step, Macro, Functions and more

create unique id for different patients-multiple rows per each

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 110
Accepted Solution

create unique id for different patients-multiple rows per each

Hi I have the following dataset were each patients have multiple rows for the same patient. I am trying to change names to an id. 

 

Name    date drug
jack    01/01/2009 a
jack    02/02/2010  b
jack   03/03/2001   c
bob   01/01/2001   d
bob   02/02 /2002   e

I want the following output 

Name    date drug    id 
jack    01/01/2009 a  1 
jack    02/02/2010  b  1
jack   03/03/2001   c   1
bob   02/02 /2002   e  2
bob   01/01/2001    d  2

Accepted Solutions
Solution
‎10-12-2016 10:36 AM
Respected Advisor
Posts: 4,644

Re: create unique id for different patients-multiple rows per each

Simple, if your data is sorted by name:

 

data want;
set have; by name;
id + first.name;
run;
PG

View solution in original post


All Replies
Solution
‎10-12-2016 10:36 AM
Respected Advisor
Posts: 4,644

Re: create unique id for different patients-multiple rows per each

Simple, if your data is sorted by name:

 

data want;
set have; by name;
id + first.name;
run;
PG
Frequent Contributor
Posts: 110

Re: create unique id for different patients-multiple rows per each

Thank you!

☑ This topic is SOLVED.

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

Discussion stats
  • 2 replies
  • 194 views
  • 2 likes
  • 2 in conversation