BookmarkSubscribeRSS Feed
CathyVI
Lapis Lazuli | Level 10

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
Lapis Lazuli | Level 10

@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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 724 views
  • 0 likes
  • 2 in conversation