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.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.