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

sas-innovate-2024.png

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.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 843 views
  • 3 likes
  • 3 in conversation