🔒 This topic is solved and locked.
Need further help from the community? Please
sign in and ask a new question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 08-28-2018 03:12 PM
(1298 views)
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you! I had to change the 4 to 6. Other than that it worked!