Help using Base SAS procedures

How to delete a character

Accepted Solution Solved
Reply
Contributor L_L
Contributor
Posts: 56
Accepted Solution

How to delete a character


Dear

I have to "clean" a variable (eliminating ~ when is at the beginning or at the end of the variable)  that occurs in this way:

active1~active2 ~ ~

active1~ ~~ ~

~active2

active3 ~active4 (it's OK)

Have you got any idea?

Thanks in advance for any help

Kind regards


Accepted Solutions
Solution
‎05-20-2014 09:09 AM
Respected Advisor
Posts: 3,124

Re: How to delete a character

This is a job for PRX functions, such as

data test;

input var $ 50.;

new_var=prxchange('s/^(~| )+|(~| )+$//io',-1,var);

cards;

active1~active2 ~ ~

active1~ ~~ ~

~active2

~~ ~active3 ~active4

;

Regards,

Haikuo

View solution in original post


All Replies
Super User
Super User
Posts: 7,413

Re: How to delete a character

Several, try tranwrd(string,"~",""), the replace function, loop over the character array etc.  Check out string functions SAS help documentation.

Solution
‎05-20-2014 09:09 AM
Respected Advisor
Posts: 3,124

Re: How to delete a character

This is a job for PRX functions, such as

data test;

input var $ 50.;

new_var=prxchange('s/^(~| )+|(~| )+$//io',-1,var);

cards;

active1~active2 ~ ~

active1~ ~~ ~

~active2

~~ ~active3 ~active4

;

Regards,

Haikuo

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 172 views
  • 0 likes
  • 3 in conversation