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_
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 =*/
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 =*/
Thank you, it worked.
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.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.