Help using Base SAS procedures

Assigning Same Numbers for Duplicate Records

Reply
New Contributor
Posts: 3

Assigning Same Numbers for Duplicate Records

Hi,

I have been tasked to assign the same numbers (not increments) for duplicate records.  Here is an example of what I want to accomplish:

ID Code    Number

A               1

B               2

C               3

D               4

D               4

E               5

F               6

G              7

G              7

G              7

Thanks!

Valued Guide
Posts: 765

Re: Assigning Same Numbers for Duplicate Records

hi ..., if data are sorted by IDCODE ...

data new;

set old;

by idcode;

number+first.idcode;

run;

ps take a look at ... http://www.sascommunity.org/wiki/Tips:Between_and_Within_Group_Counters

New Contributor
Posts: 3

Re: Assigning Same Numbers for Duplicate Records

Thanks dude,

I didn't want to write 20+ if-then statements for each letter of the alphabet lol...

Super User
Posts: 9,656

Re: Assigning Same Numbers for Duplicate Records

ScottyB_73 wrote:

Thanks dude,

I didn't want to write 20+ if-then statements for each letter of the alphabet lol...

In your sample data , there is only one variable idcode .

The same with Mike, Assuming you have sorted dataset by idcode.

data want;

set have;

if idcode ne lag(idcode) then number+1;

run;

Ask a Question
Discussion stats
  • 3 replies
  • 250 views
  • 0 likes
  • 3 in conversation