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
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;
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;
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;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.