Is there a way I can use multiple prxchange in one go. i want to replace a with d, b with k, c with l, d with a ,
Here is my input
data a;
input_string="abcdjhj";
input_num=12;
input_string2= "robin";
run;
data b;
set a;
changed_string=prxchange('s/a/d/',-1,input_string);
changed_string=prxchange('s/b/k/',-1,input_string);
changed_string=prxchange('s/c/l/',-1,input_string);
changed_string=prxchange('s/d/a/',-1,input_string);
run;
as per logic i want changed_string value to be "ddklajhj" but this is not producing correct output and my table b has 16 such character variables i want to apply the same logic for those variables also. Can someone help me with the same
Thanks in advance. Any help is appreciated
First a question, in your real data are you changing single letters or longer strings?
Second this "want changed_string value to be "ddklajhj" " does not match the description " replace a with d, b with k, c with l, d with a" If we are starting with "abcdjhj" which is 7 characters we don't get "ddklajhj" which is 8 characters.
Assuming your are replacing single characters and that you have a typo in the changed string above:
data example; input_string="abcdjhj"; newstring = translate(input_string,"dkla","abcd"); run;
TRANSLATE function is only single character replacements which is why I asked. If you have a double-byte character set the function would be KTRANSLATE.
First a question, in your real data are you changing single letters or longer strings?
Second this "want changed_string value to be "ddklajhj" " does not match the description " replace a with d, b with k, c with l, d with a" If we are starting with "abcdjhj" which is 7 characters we don't get "ddklajhj" which is 8 characters.
Assuming your are replacing single characters and that you have a typo in the changed string above:
data example; input_string="abcdjhj"; newstring = translate(input_string,"dkla","abcd"); run;
TRANSLATE function is only single character replacements which is why I asked. If you have a double-byte character set the function would be KTRANSLATE.
What value would you expect changed_string to have if you ran:
changed_string='1';
changed_string='2';
changed_string='3';
Do you see what your problem is?
Or let's do it with numbers:
x=1;
y=x+2;
y=x+3;
y=x+4;
How should you modify those four statements so that y ends up with 10?
x=1;
y=x+2;
y=y+3;
y=y+4;
Can you apply the same thing to your assignment statements?
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.
Ready to level-up your skills? Choose your own adventure.