Assign the same ID for mulitple observations

Reply
New Contributor
Posts: 2

Assign the same ID for mulitple observations

Dear SAS Community,

I need some expert advice.

I want to reassign people to the same ID if they have had >1 intervention.

Currently the dataset has assigned a new ID for every row irrespective of whether the individual has had one or more interventions.

The dataset currently looks as follows:

studyid   birth_dt intervn

68466     17564      1   

68467     18845      1

68468     18625      1

68469     20287      2

68470     20937      3

....and so on......

I would like the dataset to look like this - so keep the original study id but create a new ID that will ensure that patients who received multiple (>1) interventions are assigned the same ID and not have a consecutive (new) ID.

id        birth_dt   intervn

68466     17564      1   

68467     18845      1

68468     18625      1

68468     20287      2

68468     20937      3

....and so on...........

Any help that anyone can provide would be greatly appreciated!!

Thanks,

Alex

Respected Advisor
Posts: 4,817

Re: Assign the same ID for mulitple observations

Turns out to be a simple task :

data want;

set have;

if intervn = 1 then id + 1;

run;

PG

PG
New Contributor
Posts: 2

Re: Assign the same ID for mulitple observations

Many thanks for this. Really helpful!

Trusted Advisor
Posts: 1,228

Re: Assign the same ID for mulitple observations

data want;

set have;

n=_n_- intervn;

run;


proc sql;

create table final(drop=studyid n) as

select *,min(studyid) as id from want

group by n

order by n,intervn;

quit;

Ask a Question
Discussion stats
  • 3 replies
  • 230 views
  • 6 likes
  • 3 in conversation