Desktop productivity for business analysts and programmers

Calculating a new column

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 9
Accepted Solution

Calculating a new column

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 

 

 


Accepted Solutions
Solution
3 weeks ago
Super Contributor
Posts: 456

Re: Calculating a new column

Posted in reply to Mairam2345

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


All Replies
Solution
3 weeks ago
Super Contributor
Posts: 456

Re: Calculating a new column

Posted in reply to Mairam2345

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
Frequent Contributor
Posts: 79

Re: Calculating a new column

Posted in reply to Mairam2345

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
☑ This topic is solved.

Need further help from the community? Please ask a new question.

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