BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sasuser1000
Calcite | Level 5

tI have several sequences,

I want to replace part of my sequence with a txt but for some reson the  full sequence is replaced

so for example

replace this 1111 with dir4_

so for the sequence  11110 the result should be equal to dir4_0

%MACRO MANIP(STATE);

x1=cat(cat(&state,4),'_'); /*the value of this is dir4_*/

=tranwrd(test,"1111",x1); /*test =11110 and it's a char*/

%MEND

%MANIP('DIR')

instead of  dir4_0 the result is dir4_

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

X1 is 200 characters long padded by blanks so after the replacement from X1 there are blanks and the resultant _0 is pushed outside of the limit default 200 characters.

try

=tranwrd(test,"1111",strip(x1)); /* and shouldn't there be a variable on the left of the =*/

View solution in original post

3 REPLIES 3
ballardw
Super User

X1 is 200 characters long padded by blanks so after the replacement from X1 there are blanks and the resultant _0 is pushed outside of the limit default 200 characters.

try

=tranwrd(test,"1111",strip(x1)); /* and shouldn't there be a variable on the left of the =*/

sasuser1000
Calcite | Level 5

Thank you, it worked.

Amir
PROC Star

Hi,

The code that was posted would not run as is so I made a few amendments whilst trying to keep the code as close to the original.

I believe the issue is to do with the cat function returning a string of length 32,767. So using the trim function I believe helps find the required value for x2:

%MACRO MANIP(STATE);

  test ='11110';

  x1=cat(cat(&state,4),'_'); /*the value of this is dir4_*/

  x2=tranwrd(test,"1111",trim(x1)); /*test =11110 and it's a char*/

%MEND;

data want;

  %MANIP('DIR');

  put _all_;

run;

Regards,

Amir.

sas-innovate-wordmark-2025-midnight.png

Register Today!

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.


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
  • 3 replies
  • 1170 views
  • 3 likes
  • 3 in conversation