BookmarkSubscribeRSS Feed
gonzy31
Calcite | Level 5

Hi all,

 

Would love some help with this, as I think I am doing something wrong here in SAS.  I merged multiple years of data, but I wanted to create a unique ID variable ("ID") to identify each unique physician ("phycode").  For each individual year, the "phycode" is unique for every physician.  However, the "phycode" is repeated in subsequent years for other physicians so both "phycode" and "year" are necessary to create a new unique ID in the dataset.

 

Here is what my data looks like now:

 

Phycode        Year

1                     2004

1                     2005

2                     2004

2                     2005

3                     2004

4                     2004

 

I want my output to produce a table like this in recognition that repeat phycodes in different years represent unique physicians (ID):

 

Phycode        Year              ID

1                     2004             1

1                     2005             2

2                     2004             3

2                     2005             4

3                     2004             5

4                     2004             6

 

 

Here is what I tried:

proc sort data=IN.NAMCS0514;

by phycode year;
run; 
 
data=UniqueID;
set NSS0514;
by phycode year;
if  first.phycode then ID=1;
ID +1;
run;

 

Thanks in advance for your help

3 REPLIES 3
Astounding
PROC Star

Well you could replace the last two statements with:

 

if first.year then ID + 1;

 

Alternatively, you don't really need an ID variable,  You could just use the combination of PHYCODE and YEAR to identify a physician.

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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