I am trying to find the equivalent of the Stata code "egen group" in SAS. The goal is: I have three variables x, y, and z. I want to create a new variable which will assign a different ordinal number for each combination of values of x, y, and z. How can I do this in SAS?
With hope I understand you correctly, use next code:
proc sort data=have; by x y z; run;
data new;
set have;
by x y z;
retain key;
if first.z then key+1;
run;
With hope I understand you correctly, use next code:
proc sort data=have; by x y z; run;
data new;
set have;
by x y z;
retain key;
if first.z then key+1;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.