BookmarkSubscribeRSS Feed
hashman
Ammonite | Level 13

@ScottBass :

Agree that it would be cool to have a canned function to find the index of the Kth occurrence of a character or word.

Would be neater, as you suggest, to add an extra argument to an existing function, but if my conversations with Rick L. are any indicator, overloading existing SAS functions is much more problematic than creating new ones (I once tried to coax him into adding a parm to the CATs family to specify a format other than the default for auto-converting numeric arguments, and the above was what he said). 

 

On the other note, the problem with the regexen is that those who don't get to use them often (or, better still, day in and day out) have to spend an inordinate time with the docs to comprehend what an expression means and does. So, simpletons like myself in cases like the subject of this thread tend to use something simpler and more readily recognizable, even at the expense of performance (as the regexen are really quite fast).  

 

Kind regards

Paul D.

ChrisNZ
Tourmaline | Level 20

@hashman  My experience is that Regular Expressions are much more expensive than the "normal" string functions.

 

And since they are less legible too as you mention, they are not my first choice either.

 

However, their power means that sometimes they are the only sensible option, as they can replace tens or even hundreds of lines of code where numerous combinations would have to be tested resulting in un-maintainable spaghetti code.

 

data _null_;   * 0.4 seconds;
  A='a, b, cd, ef, gdjh';
  do I=1 to 1e7;
    call scan(A,4,POS,LEN,',');
    POS=POS-1;
  end;
  put POS=;
run;

data _null_;  * 7.5 seconds;
  A='a, b, cd, ef, gdjh';
  do I=1 to 1e7;
    POS=length(prxchange('s/(([^,]*,){3}).*/\1/o',1,A));
  end;
  put POS=;
run;

 

 

 

hashman
Ammonite | Level 13

@ChrisNZ : 

True. The reason I've mentioned the regexen's purported efficiency is that once on SAS-L someone (unfortunately, don't remember who or the circumstances) showed a regex - which I then tested - that worked much faster than the combos of string functions anyone else (including me) had offered. Could be a fluke ... but got seared in my memory nonetheless.  

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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
  • 17 replies
  • 1681 views
  • 13 likes
  • 6 in conversation