I have a panel dataset and need to create an ID for groups of variables based on unique combination of (Year, LoadPort, DischargePort). There are other variables I would like to retain in the dataset but aren’t needed to identify the group. For example:
Year LoadPort DischargePort ID
2007 ARZEW LOOP TERMINAL 1
2008 ARZEW LOOP TERMINAL 1
2011 RAS TANURA ZHONGSHAN 2
2010 RAS TANURA ZHONGSHAN 2
I need to create the last column. This is what I have tried but it gives me nonsense results:
proc sort data=data.benchmark5;
by loadport dischargeport year;
run;
data data.benchmark6;
set data.benchmark5;
retain ID;
by loadport dischargeport year;
if first.year then ID = 0;
ID = ID + 1;
run;
This would give you the ID as your sample shows.