BookmarkSubscribeRSS Feed
CathyVI
Pyrite | Level 9

Hello,
I have dummy variable Var1 and Var2.
How will I remove the 2 in R862 so as to have R86 and R86 in both Var1 and Var2.
I will like to do this for all the unmatched e.g. C23 and C2357, E89 and E8996 etc. I have over 10,000 encounters my dataset with this issue.

Fname  Lname  Firstname  Lastname  Var1   Var2
John     Doe      John           Do             J124   J124
Pat       Cut        Patt            Cot jr         C23    C2357
Riley     Jo Sr     Rilly           Joo            R862  R86
Ellen     Mee      Elen           Meey Sr.    E89    E8996

3 REPLIES 3
Reeza
Super User
Please provide more details.
For starters, if that was your input what do you want as output.
CathyVI
Pyrite | Level 9

@Reeza I want my output to be matched result for the two dummy variables. I will like to remove the extra numbers from each row. This is want I want my output to looks like.

Var1  Var2

J124 J124

C23  C23

R86  R86

E89  E89

Reeza
Super User

Check the lengths of each variable and whichever is the smaller, use that and assign it to both variables.

Something like this perhaps:

 

if length(var1) < length(var2) then var2=var1;
else var1=var2;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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