DATA Step, Macro, Functions and more

How to character string from a sentence

Reply
Super Contributor
Posts: 270

How to character string from a sentence

Dear,

 

I have variable(value) whose values contain 'NCS' . I need to remove the string. Please help.

 

Thanks 

 

             value
"sentence of words NCS"

"sentence of words (NCS)"
"NCS , sentence of words"
"NCS sentence of words"
"NCS; sentence of words"

Super User
Posts: 17,750

Re: How to character string from a sentence

Look at TRANWRD function 

Super Contributor
Posts: 254

Re: How to character string from a sentence

You may try COMPRESS function too.

 

new_Value = compress(Value, 'NCS',' ');

 

You have comma, semicolon, '(' and ')'.

 

These also can be compressed into blanks or none.

Super User
Posts: 9,662

Re: How to character string from a sentence

You didn't post then output yet.



data have;
input value $quote40.;
cards4;
"sentence of words NCS"
"sentence of words (NCS)"
"NCS , sentence of words"
"NCS sentence of words"
"NCS; sentence of words"
;;;;
run;
data want;
 set have;
 new_value=prxchange('s/\bNCS\b//i',-1,value);
run;

Super Contributor
Posts: 270

Re: How to character string from a sentence

Hi 

Thanks for the help. It worked, but removed only 'NCS' characters only.

 

output;

 

"sentence of words "
"sentence of words ()"
" , sentence of words"
" sentence of words"
"; sentence of words"
Super User
Posts: 9,662

Re: How to character string from a sentence

Then what output do you expect ?
Ask a Question
Discussion stats
  • 5 replies
  • 287 views
  • 4 likes
  • 4 in conversation