Replace the @ with any string you want. Just make sure that you aren't using something that regex considers a command. You can use backslash to escape special characters like \ or / or * or + etc.
Thank you
OK. I found an interesting ERROR information.
Try this nested one :
data str;
x = "I have a very long string length, I want to insert a character after every 15 character. If not enough characters at the end then, ignore it.";
length want $ 400;
want= prxchange('s/(.{16})/\1@/',-1,prxchange('s/(.{15})/\1@/',-1,x));
run;
Thank you @Ksharp
According to the documentation, the @ sign should be escaped at least in the search pattern.
{ } [ ] ( ) ^ $ . | * + ? \ @
to match these characters, override (escape) with \.
It appears that the double @ causes an ambiguity even in the replacement text, but escaping works there as well: In fact, both \@@ and \@\@ create the desired @@ in the replacement text.
Thank you
Thank you, @Ksharp. I want to make this tricky, if it possible, please let me know.
"I have a very long string length, I want to insert a character after every 15 characters. If not enough characters at the end then, ignore it."
I am looking for
if the 15th character is " " (space) then it can insert the "@" symbol.
if the 15th character is in the middle of the word, then it has to insert the symbol " "(space) before the 15th character and repeat the same. ( in the above string letter "l' is the 15th character and it's the middle of the word, so I am looking for my insert to move to 'space' before the word 'long').
This concept I am applying to write the long footnotes in RTF from the excel sheet using the macro. With help of all you guys I am able to achieve to 90% of what I am looking. I was inserting a ODS ESCAPECHAR symbol after certain length so that the text starts in the next line. I am trying to avoid the Splitting of the words like (from word 'long' , 'l' in one line and new line starts with 'ong').
I am not sure its very efficient or possible, but giving a try.
/*
OK. Then you don't need PRX .SCAN() can do that.
*/
data str;
x = "I have a very long string length, I want to insert a character after every 15 character. If not enough characters at the end then, ignore it.";
length want $ 600;
do i=1 to countw(x,' ');
temp=scan(x,i,' ');
_want=want;
want=catx(' ',want,temp);
if length(scan(want,-1,'@'))>15 then want=catx('@',_want,temp);
end;
drop i temp _want;
run;
Thank you.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.