SAS Enterprise Guide

Desktop productivity for business analysts and programmers
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
kfbaker0206
Fluorite | Level 6

I am trying to change the 4th character in a string. The 4th character consists of numbers and letters. The code that I used changes the entire string to all x's. Please see code. Any assistance will be greatly appreciated. 

 

Data Want;
	set DATASET1;
do _N_=2 TO length(code);
substr(code,_n_,4)=byte(mod(rank(char(code,_n_))+&offset,255));
end;
run;
This is the original data 
DATASET 1
CODE
0S124
0R123
0T435
0F5F3
0R4RY

 

This is what I want 
DATASET 2
CODE
0S1X4
0R1X3
0T4X5
0F5X3
0R4XY

 

Here are my results
CODE
XXXXX
XXXXX
XXXXX
XXXXX
XXXXX
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

This works. Use the Left of = SUBSTR function. Not sure why you're looping anything or using _N_.

 

data want;
set sashelp.class;

substr(name, 4, 1) = 'X';

run;

View solution in original post

2 REPLIES 2
Reeza
Super User

This works. Use the Left of = SUBSTR function. Not sure why you're looping anything or using _N_.

 

data want;
set sashelp.class;

substr(name, 4, 1) = 'X';

run;
kfbaker0206
Fluorite | Level 6

Thank you! I had to change the 4 to 6. Other than that it worked! 

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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