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',' '));
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.