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

 X=”GTTCACTAGCAACCTCAAACAGACACCATGGTGCACCTG”

 

a=”-CCTCA”

b=”A-CTCA”

c=”AC-TCA”

d=”ACC-CA”

e=”ACCT-A”

f=”ACCTC-”

 

“-“ is any one letter, such as “G” “T” or “A”;

I thought a,b,c,d,e,f are all equal to pattern “ACCTCA”

How can I write an index function to find the position of a (or b, or c, or d, or e, or f) in X; 

 

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

You say "pattern" I think RegEx. Below a variation of what has already been proposed.

data sample;
  input string:$60.;
  match_pos= prxmatch('/(.CCTCA|A.CTCA|AC.TCA|ACC.CA|ACCT.A|ACCTC.)/oi',string);
  match_flg= prxmatch('/(.CCTCA|A.CTCA|AC.TCA|ACC.CA|ACCT.A|ACCTC.)/oi',string)>0;
  datalines;
GTTCACTAGCAACCTCAAACAGACACCATGGTGCACCTG
GTTCACTAGCACACTCAAACAGACACCATGGTGCACCTG
;
run;

View solution in original post

7 REPLIES 7
LaurieF
Barite | Level 11

I'm no great Perl maven, but using prxmatch will give you what you're after. Here's how I did it:

 

data _null_;
infile cards;
retain x "GTTCACTAGCAACCTCAAACAGACACCATGGTGCACCTG";
length pattern $ 9;
input pattern;
match = prxmatch('/' || strip(pattern) || '/', x);
put match=;
cards;
.CCTCA
A.CTCA
AC.TCA
ACC.CA
ACCT.A
ACCTC.
;
run;

In Perl, the wild card is '.', not '-'.

 

When this code is run, the pattern is found at position 12 every time. If it weren't found, like with index, it would return 0.

Niugg2010
Obsidian | Level 7

Thanks a lot. I never used prxmatch function. I will try it.

Patrick
Opal | Level 21

find() or index() don't allow for wildcard searches.

 

You could either use a Regular Expression or a Like operator in a where clause.

 

Would you just need the first position where one of your patterns matches? And would ALL patterns have to match or only one of them?

Reeza
Super User

Also, look into COMPGED, Complev and other functions. 

Not sure they'll give you enough control though. 

Niugg2010
Obsidian | Level 7

 X=”GTTCACTAGCAACCTCAAACAGACACCATGGTGCACCTG”
pattern="ACCTCA" or pattern="A-CTCA"


Actually I want to check " if X contains pattern "; 
I found I can not  use this logistic judgement,

So I thought maybe I can use index() function,

if result >0 it means X contains pattern;

if result =0 it means X does not contains pattern.

 

if someone can suggest a better method, it will be great. 

Patrick
Opal | Level 21

You say "pattern" I think RegEx. Below a variation of what has already been proposed.

data sample;
  input string:$60.;
  match_pos= prxmatch('/(.CCTCA|A.CTCA|AC.TCA|ACC.CA|ACCT.A|ACCTC.)/oi',string);
  match_flg= prxmatch('/(.CCTCA|A.CTCA|AC.TCA|ACC.CA|ACCT.A|ACCTC.)/oi',string)>0;
  datalines;
GTTCACTAGCAACCTCAAACAGACACCATGGTGCACCTG
GTTCACTAGCACACTCAAACAGACACCATGGTGCACCTG
;
run;
Niugg2010
Obsidian | Level 7

Thanks a lot. It is very helpful.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 7 replies
  • 1401 views
  • 2 likes
  • 4 in conversation