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

Hi Guys,

I have a string where the value I wish to extract varies from observation to observation.  I have created the following code as an example:

DATA STUFF;

STRING = '"><ahref"/browse/601/0/3"><imgsrc="/static/img/prev.gif"border="0"alt="Previous"/></a> <ahref="/browse/601/0/3">1</a> 2 <ahref="/browse/601/2/3">3</a> <ahref="/browse/601/3/3">4</a> <ahref="/browse/601/4/3">5</a> <ahref="/browse/601/5/3">6</a> <ahref="/browse/601/6/3">7</a> <ahref="/browse/601/7/3">8</a> <ahref="/browse/601/8/3">9</a> <ahref="/browse/601/9/3">10</a> <ahref="/browse/601/10/3">11</a> <ahref="/browse/601/11/3">12</a> <ahref="/browse/601/12/3">13</a> <ahref="/browse/601/13/3">14</a> <ahref="/browse/601/14/3">15</a> <ahref="/browse/601/15/3">16</a> <ahref="/browse/601/16/3">17</a> <ahref="/browse/601/17/3">18</a> <ahref="/browse/601/18/3">19</a> <ahref="/browse/601/19/3">20</a> <ahref="/browse/601/20/3">21</a> <ahref="/browse/601/21/3">22</a> <ahref="/browse/601/22/3">23</a> <ahref="/browse/601/23/3">24</a> <ahref="/browse/601/24/3">25</a> <ahref="/browse/601/25/3">26</a> <ahref="/browse/601/26/3">27</a> <ahref="/browse/601/27/3">28</a> <ahref="/browse/601/28/3">29</a> <ahref="/browse/601/29/3">30</a> <ahref="/browse/601/2/3"><imgsrc="/static/img/next.gif"border="0"alt="Next"/></a> ';

PATTERN = PRXPARSE('#"/browse/\d+\/\d+/\d+"><imgsrc="/static/img/next.gif"border="0"alt="Next"/></a> #');

CALL PRXSUBSTR(PATTERN,STRING,START,LENGTH);

SUB = SUBSTR(STRING,START,LENGTH);

RUN;

The result looks like sub = "/browse/601/2/3"><imgsrc="/static/img/next.gif"border="0"alt="Next"/></a> .  However I really want to return only the  "/browse/601/2/3" portion.  Obviously there are numerous ways to do this using non-prx functions, however I was hoping that there was a PRX method I could employ without creating a separate prx pattern to match this substring as below.

DATA STUFF;

LENGTH SUB $80 SUB1 $15;

STRING = '"><ahref"/browse/601/0/3"><imgsrc="/static/img/prev.gif"border="0"alt="Previous"/></a> <ahref="/browse/601/0/3">1</a> 2 <ahref="/browse/601/2/3">3</a> <ahref="/browse/601/3/3">4</a> <ahref="/browse/601/4/3">5</a> <ahref="/browse/601/5/3">6</a> <ahref="/browse/601/6/3">7</a> <ahref="/browse/601/7/3">8</a> <ahref="/browse/601/8/3">9</a> <ahref="/browse/601/9/3">10</a> <ahref="/browse/601/10/3">11</a> <ahref="/browse/601/11/3">12</a> <ahref="/browse/601/12/3">13</a> <ahref="/browse/601/13/3">14</a> <ahref="/browse/601/14/3">15</a> <ahref="/browse/601/15/3">16</a> <ahref="/browse/601/16/3">17</a> <ahref="/browse/601/17/3">18</a> <ahref="/browse/601/18/3">19</a> <ahref="/browse/601/19/3">20</a> <ahref="/browse/601/20/3">21</a> <ahref="/browse/601/21/3">22</a> <ahref="/browse/601/22/3">23</a> <ahref="/browse/601/23/3">24</a> <ahref="/browse/601/24/3">25</a> <ahref="/browse/601/25/3">26</a> <ahref="/browse/601/26/3">27</a> <ahref="/browse/601/27/3">28</a> <ahref="/browse/601/28/3">29</a> <ahref="/browse/601/29/3">30</a> <ahref="/browse/601/2/3"><imgsrc="/static/img/next.gif"border="0"alt="Next"/></a> ';

PATTERN = PRXPARSE('#"/browse/\d+\/\d+/\d+"><imgsrc="/static/img/next.gif"border="0"alt="Next"/></a> #');

PATTERN1 = PRXPARSE('#/browse/\d+\/\d+/\d+#');

CALL PRXSUBSTR(PATTERN,STRING,START,LENGTH);

SUB = SUBSTR(STRING,START,LENGTH);

CALL PRXSUBSTR(PATTERN1,SUB,START1,LENGTH1);

SUB1 = SUBSTR(SUB,START1,LENGTH1);

RUN;

Thank you very much for your help.

Regards,

Scott

1 ACCEPTED SOLUTION

Accepted Solutions
FriedEgg
SAS Employee

Better to exploit capture-buffers available through PRX then doing a substr, try something like:

string='"><ahref"/browse/601/0/3"><imgsrc="/static/img/prev.gif"border="0"alt="Previous"/></a> <ahref="/browse/601/0/3">1</a> 2 <ahref="/browse/601/2/3">3</a> <ahref="/browse/601/3/3">4</a> <ahref="/browse/601/4/3">5</a> <ahref="/browse/601/5/3">6</a> <ahref="/browse/601/6/3">7</a> <ahref="/browse/601/7/3">8</a> <ahref="/browse/601/8/3">9</a> <ahref="/browse/601/9/3">10</a> <ahref="/browse/601/10/3">11</a> <ahref="/browse/601/11/3">12</a> <ahref="/browse/601/12/3">13</a> <ahref="/browse/601/13/3">14</a> <ahref="/browse/601/14/3">15</a> <ahref="/browse/601/15/3">16</a> <ahref="/browse/601/16/3">17</a> <ahref="/browse/601/17/3">18</a> <ahref="/browse/601/18/3">19</a> <ahref="/browse/601/19/3">20</a> <ahref="/browse/601/20/3">21</a> <ahref="/browse/601/21/3">22</a> <ahref="/browse/601/22/3">23</a> <ahref="/browse/601/23/3">24</a> <ahref="/browse/601/24/3">25</a> <ahref="/browse/601/25/3">26</a> <ahref="/browse/601/26/3">27</a> <ahref="/browse/601/27/3">28</a> <ahref="/browse/601/28/3">29</a> <ahref="/browse/601/29/3">30</a> <ahref="/browse/601/2/3"><imgsrc="/static/img/next.gif"border="0"alt="Next"/></a> ';

prxid=prxparse('#(/browse/\d+/\d+/\d+)"><imgsrc#');

if prxmatch(prxid) then x=prxposn(prxid,1,string);

View solution in original post

3 REPLIES 3
FriedEgg
SAS Employee

Better to exploit capture-buffers available through PRX then doing a substr, try something like:

string='"><ahref"/browse/601/0/3"><imgsrc="/static/img/prev.gif"border="0"alt="Previous"/></a> <ahref="/browse/601/0/3">1</a> 2 <ahref="/browse/601/2/3">3</a> <ahref="/browse/601/3/3">4</a> <ahref="/browse/601/4/3">5</a> <ahref="/browse/601/5/3">6</a> <ahref="/browse/601/6/3">7</a> <ahref="/browse/601/7/3">8</a> <ahref="/browse/601/8/3">9</a> <ahref="/browse/601/9/3">10</a> <ahref="/browse/601/10/3">11</a> <ahref="/browse/601/11/3">12</a> <ahref="/browse/601/12/3">13</a> <ahref="/browse/601/13/3">14</a> <ahref="/browse/601/14/3">15</a> <ahref="/browse/601/15/3">16</a> <ahref="/browse/601/16/3">17</a> <ahref="/browse/601/17/3">18</a> <ahref="/browse/601/18/3">19</a> <ahref="/browse/601/19/3">20</a> <ahref="/browse/601/20/3">21</a> <ahref="/browse/601/21/3">22</a> <ahref="/browse/601/22/3">23</a> <ahref="/browse/601/23/3">24</a> <ahref="/browse/601/24/3">25</a> <ahref="/browse/601/25/3">26</a> <ahref="/browse/601/26/3">27</a> <ahref="/browse/601/27/3">28</a> <ahref="/browse/601/28/3">29</a> <ahref="/browse/601/29/3">30</a> <ahref="/browse/601/2/3"><imgsrc="/static/img/next.gif"border="0"alt="Next"/></a> ';

prxid=prxparse('#(/browse/\d+/\d+/\d+)"><imgsrc#');

if prxmatch(prxid) then x=prxposn(prxid,1,string);

Scott_Mitchell
Quartz | Level 8

Thanks guys, that was perfect.

Patrick
Opal | Level 21

you could try and use look ahead and look behind as part of your RegEx.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 1737 views
  • 5 likes
  • 3 in conversation