DATA Step, Macro, Functions and more

How to character string from a sentence

Reply
Super Contributor
Posts: 272

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: 19,815

Re: How to character string from a sentence

Posted in reply to knveraraju91

Look at TRANWRD function 

Super Contributor
Posts: 298

Re: How to character string from a sentence

Posted in reply to knveraraju91

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: 10,028

Re: How to character string from a sentence

Posted in reply to knveraraju91
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: 272

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: 10,028

Re: How to character string from a sentence

Posted in reply to knveraraju91
Then what output do you expect ?
Ask a Question
Discussion stats
  • 5 replies
  • 293 views
  • 4 likes
  • 4 in conversation