BookmarkSubscribeRSS Feed
Kelroy22
Fluorite | Level 6

*There is a earlier topic describing how to replace multiple targets using tranwrd in a loop function. Unfortunately it is somehow not working for all types of Words that I want to replace.

 

In the below code I want to remove. "koncern-LK.ramme" but the function fails to do so. Does anybody know what I am doing wrong?. Thx

 

data x;

set y;

newName = OldName;

do word="kon.-LK", "koncern-LK.ramme";

newName = tranwrd(' '||newName, ' '||strip(word)||' ', ' ');

end;

newName  = compbl(newName );

drop word;

run;

1 REPLY 1
s_lassen
Meteorite | Level 14

@Kelroy22:

Your problem is probably the length of the WORD variable - the DO statement initializes the variable to the length of the first value in the iteration, as you can see from this log:

1507  data _null_;
1508    do word="kon.-LK", "koncern-LK.ramme";
1509      put word;
1510      end;
1511  run;

kon.-LK
koncern

If you add a LENGTH statement it should work:

1512  data _null_;
1513    length word $20;
1514    do word="kon.-LK", "koncern-LK.ramme";
1515      put word;
1516      end;
1517  run;

kon.-LK
koncern-LK.ramme

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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
  • 1 reply
  • 1755 views
  • 0 likes
  • 2 in conversation