you can use prxchange again.
new_string = prxchange('s/1\/2//', -1, text2);
you can use prxchange again.
new_string = prxchange('s/1\/2//', -1, text2);
Read the documentation a bit more carefully:
Returns a character string with specified characters removed from the original string (emphasis added for character not string of characters)
So Compress removes all the characters you provide.
If you want to replace a specific sequence of characters you might try TRANSTR
Data have; infile datalines truncover; input var $100.; want = transtrn(var,'1/2',''); Cards; 20 1/2 Apple ; Run;
Note changes to your data step to actually read the value of VAR.
COMPRESS() is NOT what you want. That removes CHARACTERS.
So all of these statements are the same:
var=compress(var, '1/2') ;
var=compress(var, '12/') ;
var=compress(var, '/12') ;
var=compress(var, '21/') ;
You want TRANWRD() or TRANSTRN() instead. You can use COMPBL() collapse multiple adjacent spaces into just one space.
var=compbl(tranwrd(var,'1/2',' '));
April 27 – 30 | Gaylord Texan | Grapevine, Texas
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!
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.
Ready to level-up your skills? Choose your own adventure.