BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Salsalvr
Calcite | Level 5

 

I'm looking for a way to create a unique Identifier that will account for duplicates of a client based on an old client ID.  Please see below.

I tried a do loop but it just hung up on me.  Does anyone know code for this. Thanks.

 

Old _ClientID    NewID

564                         1

564                         1

345                         2

367                         3

321                         4

111                         5

111                         5

111                         5

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

If you are starting with Old_ClientID and want to get NewID, you can use:

 

data want;

set have;

by Old_ClientID notsorted;

if first.Old_ClientID then NewID + 1;

run;

 

It's important that the incoming data is grouped properly.  For example, all the "564" values have to appear consecutively within the incoming data.

View solution in original post

3 REPLIES 3
Astounding
PROC Star

If you are starting with Old_ClientID and want to get NewID, you can use:

 

data want;

set have;

by Old_ClientID notsorted;

if first.Old_ClientID then NewID + 1;

run;

 

It's important that the incoming data is grouped properly.  For example, all the "564" values have to appear consecutively within the incoming data.

Salsalvr
Calcite | Level 5
Thank you so much. That worked perfectly.
kiranv_
Rhodochrosite | Level 12

 way to do this

proc sql;
create table want as 
select Old_ClientID , 
	   (select count(distinct Old_ClientID) from 
	   have b
where  a.Old_ClientID <= b.Old_ClientID) as newid 
from have a
order by newid;

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!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 1260 views
  • 1 like
  • 3 in conversation