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;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.