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

Hi Team,

 

I would like to know, if is possible to select the word in a specific interval string.


Ex: Variable name: Comments
I need select the words between PROCESS ORIGIN  and FACTS.

 

 

PROCESS ORIGIN sas communities FACTS

PROCESS ORIGIN Google Inc FACTS

PROCESS ORIGIN Google FACTS

 

Thx !!!

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

 

data want(drop=_:);
  input string&$100.;
  length want $80;
  retain _re;

  if _n_=1 then
    _re=prxparse('/\bprocess origin\b(.*)\bfacts\b/oi');

  if prxmatch(_re, trim(string)) then
    do;
      want=prxposn(_re, 1, string);
    end;

  cards;
PROCESS ORIGIN sas communities FACTS
PROCESS ORIGIN Google Inc FACTS
PROCESS ORIGIN Google FACTS
Process Original Mix by Wehbba facts
blah PROCESS ORIGIN Google Inc FACTS
blah PROCESS ORIGIN Google Inc xxFACTS
blah PROCESS ORIGIN Google Inc FACTSxx
;

 

View solution in original post

3 REPLIES 3
Jagadishkatam
Amethyst | Level 16

Please try

 

data want;
input string&$100.;
want=prxchange('s/(.*origin)(.*)(FACTS\s)/$2/i',-1,string);
cards;
PROCESS ORIGIN sas communities FACTS
PROCESS ORIGIN Google Inc FACTS
PROCESS ORIGIN Google FACTS
;
Thanks,
Jag
Patrick
Opal | Level 21

 

data want(drop=_:);
  input string&$100.;
  length want $80;
  retain _re;

  if _n_=1 then
    _re=prxparse('/\bprocess origin\b(.*)\bfacts\b/oi');

  if prxmatch(_re, trim(string)) then
    do;
      want=prxposn(_re, 1, string);
    end;

  cards;
PROCESS ORIGIN sas communities FACTS
PROCESS ORIGIN Google Inc FACTS
PROCESS ORIGIN Google FACTS
Process Original Mix by Wehbba facts
blah PROCESS ORIGIN Google Inc FACTS
blah PROCESS ORIGIN Google Inc xxFACTS
blah PROCESS ORIGIN Google Inc FACTSxx
;

 

Sk1_SAS
Obsidian | Level 7

Thank you!

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

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
  • 1265 views
  • 0 likes
  • 3 in conversation