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

Hello, 

 

I have a table of transaction data with a lot of different customer names in alphanumeric. Now i want to convert those names in a numeric variable. 

 

I would like to have the following conversion: 

 

Trans1. Customer A -> 1

Trans2. Customer B -> 2 

Trans3. Customer C-> 3

Trans4. Customer A-> 1

 

Is that possible? Can you help me pls. 

 

Thanks and regards,
Mariam 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
SuryaKiran
Meteorite | Level 14

You can sort the data by group and then use FIRST. to assign a value to that group.

data have;
input cust $;
datalines;
A
B
B
C
A
B
C
;
proc sort data=have;
by cust;
data want;
set have;
by cust;
if first.cust then ID+1;
run;
Thanks,
Suryakiran

View solution in original post

2 REPLIES 2
SuryaKiran
Meteorite | Level 14

You can sort the data by group and then use FIRST. to assign a value to that group.

data have;
input cust $;
datalines;
A
B
B
C
A
B
C
;
proc sort data=have;
by cust;
data want;
set have;
by cust;
if first.cust then ID+1;
run;
Thanks,
Suryakiran
mnjtrana
Pyrite | Level 9

Hi- If i understood correctly, you have specific values that needs to be changed to numeric .

 

In the below code, you are checking for specific values for names and assigning new_val variable to numeric values as you mentioned.

 

data need;
set have;

if name in("Trans1. Customer A" ,"Trans4. Customer A") then new_val = 1;

else if name in("Trans2. Customer B"0 then new_val = 2;

else if name in("Trans3. Customer C"0 then new_val = 3;
run;

Cheers from India!

Manjeet

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

Register Now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 2 replies
  • 1405 views
  • 3 likes
  • 3 in conversation