SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

Create ID variable for multiple records per individual

Reply
New Contributor ash
New Contributor
Posts: 4

Create ID variable for multiple records per individual

Hi,

I have an id variable, and I have multiple observations per id (patients with multiple specimens). I want to create a new ID variable containing 1 for the first ID, 2 for the second, and so on.  I have a date variable.  This in preparation for transposing the dataset to have one row per patient with columns for the variables related to specimen 1, specimen 2, etc.  Open to ideas of better ways to do this, but I was going to use the new ID variable as my prefix.

Super User
Posts: 11,343

Re: Create ID variable for multiple records per individual

Stub code:

proc sort data=have; by ID date;run;

data want;

     set have;

     by Id;

     Retain IdRec .;

     if first.id the IdRec=1;

     else IdRec+1;

run;

Ask a Question
Discussion stats
  • 1 reply
  • 324 views
  • 1 like
  • 2 in conversation