BookmarkSubscribeRSS Feed
ScottyB_73
Calcite | Level 5

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!

3 REPLIES 3
MikeZdeb
Rhodochrosite | Level 12

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

ScottyB_73
Calcite | Level 5

Thanks dude,

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

Ksharp
Super User

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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 3 replies
  • 1521 views
  • 0 likes
  • 3 in conversation