BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Tom
Super User Tom
Super User

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.

 

Ksharp
Super User
As Tom said replace @ with double @.
want=prxchange('s/(.{15})/\1@/',-1,x);
-->
want=prxchange('s/(.{15})/\1@@/',-1,x);
Ksharp
Super User

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;

Ksharp_0-1682078511549.png

 

FreelanceReinh
Jade | Level 19

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.

SASuserlot
Barite | Level 11

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.

 

Ksharp
Super User
/*
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;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

Register Now

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
  • 24 replies
  • 5692 views
  • 13 likes
  • 6 in conversation