BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
n7
Calcite | Level 5 n7
Calcite | Level 5

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?

1 ACCEPTED SOLUTION

Accepted Solutions
Shmuel
Garnet | Level 18

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;

View solution in original post

1 REPLY 1
Shmuel
Garnet | Level 18

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;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 862 views
  • 1 like
  • 2 in conversation