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.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 536 views
  • 1 like
  • 3 in conversation