BookmarkSubscribeRSS Feed
LeftHandLob
Calcite | Level 5

Okay SAS community, I'm very green in this field of Data.  I have specific field expertise, but lack the data science background, so I need a little direction:

 

I'm trying to apply sequential identifiers to a column of existing ID numbers in order to later filter out the first ID number in the original column.  There are roughly 30 columns of total data and about 500K records...big table.

 

Here are the existing ID numbers in my table:

 

6JGM92501240   
6JGM92501240
6JGM92301228
6JGM92001215
6JGM92001215
6JGM92001215
6JGM92001215
6JGM92301228
6JGM92301228

 

I would like to have this:

 

1     6JGM92501240
2     6JGM92501240
1     6JGM92301228
1     6JGM92001215
2     6JGM92001215
3     6JGM92001215
4     6JGM92001215
1     6JGM92301228
2     6JGM92301228

 

I can't simply use select distinct rows only due to some other factors.  Any idea how to do this??  Any help would be great, thanks!

4 REPLIES 4
Reeza
Super User

This post goes over how to enumerate BY groups:

https://stats.idre.ucla.edu/sas/faq/how-can-i-create-an-enumeration-variable-by-groups/

 


@LeftHandLob wrote:

Okay SAS community, I'm very green in this field of Data.  I have specific field expertise, but lack the data science background, so I need a little direction:

 

I'm trying to apply sequential identifiers to a column of existing ID numbers in order to later filter out the first ID number in the original column.  There are roughly 30 columns of total data and about 500K records...big table.

 

Here are the existing ID numbers in my table:

 

6JGM92501240   
6JGM92501240
6JGM92301228
6JGM92001215
6JGM92001215
6JGM92001215
6JGM92001215
6JGM92301228
6JGM92301228

 

I would like to have this:

 

1     6JGM92501240
2     6JGM92501240
1     6JGM92301228
1     6JGM92001215
2     6JGM92001215
3     6JGM92001215
4     6JGM92001215
1     6JGM92301228
2     6JGM92301228

 

I can't simply use select distinct rows only due to some other factors.  Any idea how to do this??  Any help would be great, thanks!


 

PaigeMiller
Diamond | Level 26
proc sort data=have;
    by id;
run;
data want;
    set have;
    by id;
    if first.id then seq=0;
    seq+1;
run;

If the data is already sorted, you can leave out the PROC SORT.

--
Paige Miller
Reeza
Super User
Just a note that I modified your subject line to make it more descriptive.
novinosrin
Tourmaline | Level 20
data have;
input id $20.;
cards;
6JGM92501240   
6JGM92501240
6JGM92301228
6JGM92001215
6JGM92001215
6JGM92001215
6JGM92001215
6JGM92301228
6JGM92301228
;

data want;
set have;
by id notsorted;
if first.id then n=1;
else n+1;
run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 4 replies
  • 15185 views
  • 3 likes
  • 4 in conversation