lydias
lydias

Reputation: 841

SAS How to extract a single string before a specific string?

I'm trying to extract the number n before a string:

DEMO_DASHBOARD_n_START_TIME

How should I extract n?

I tried, but none worked:

  id = scan(name, -1, "_START_TIME");
  id = substr(name, index(name,"_START_TIME") - 1);

The number n has to be before _START_TIME, not just a digit in the string. Therefore compress() to extract just digits should not be used.

Thanks for any inputs!

Upvotes: 0

Views: 874

Answers (1)

whymath
whymath

Reputation: 1394

So, it's time for regular expression.

Pat = prxparse('/(\d+)_START_TIME/');
if prxmatch(Pat,) then ID = prxposn(Pat,1,Name);

Upvotes: 2

Related Questions