BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ybz12003
Rhodochrosite | Level 12

Hi Experts,

 

I remember there is a SAS function which could remove all the "-" or "_" between the text, and compress the text?  But I forgot which one.   My variable is Charastatic.    Please advice.  Thanks.

 

1 ACCEPTED SOLUTION

Accepted Solutions
r_behata
Barite | Level 11
data _null_;
	want=compress("remove - or _","_-");
	put want=;
run;
25         GOPTIONS ACCESSIBLE;
26         data _null_;
27         want=compress("remove - or _","_-");
28         
29         put want=;
30         run;

want=remove  or

View solution in original post

3 REPLIES 3
r_behata
Barite | Level 11
data _null_;
	want=compress("remove - or _","_-");
	put want=;
run;
25         GOPTIONS ACCESSIBLE;
26         data _null_;
27         want=compress("remove - or _","_-");
28         
29         put want=;
30         run;

want=remove  or
ybz12003
Rhodochrosite | Level 12

I got it work, thanks.

ed_sas_member
Meteorite | Level 14

Hi @ybz12003 

 

Another possibility is to use the PRXCHANGE function:

 

data _null_;
	want=prxchange('s/(^\s*|-|_|\s*$)//',-1,"   remove - or _  ");
run;

 

It looks for the following patterns ^\s*|-|_|\s*$ as many times as needed (-1):

  • ^\s = zero, one or more (*) blanks (\s) at the beginning of the string (^)
  • \s$ = zero, one or more (*) blanks (\s) at the beginning of the string ($)
  • an hyphen (-)
  • an underscore (_)

and replace them by nothing.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 3 replies
  • 842 views
  • 1 like
  • 3 in conversation