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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 883 views
  • 3 likes
  • 3 in conversation