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;
Thanks in advance for your help
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.
Your output matches:
Thank you both! That worked perfectly.
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.
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.