DATA Step, Macro, Functions and more

proc tranwrd

Accepted Solution Solved
Reply
Contributor
Posts: 60
Accepted Solution

proc tranwrd

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_


Accepted Solutions
Solution
‎07-16-2013 01:35 PM
Super User
Posts: 10,500

Re: proc tranwrd

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


All Replies
Solution
‎07-16-2013 01:35 PM
Super User
Posts: 10,500

Re: proc tranwrd

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 =*/

Contributor
Posts: 60

Re: proc tranwrd

Thank you, it worked.

Super Contributor
Posts: 282

Re: proc tranwrd

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.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

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