Solved
Contributor
Posts: 21

# Difference in positions

Hello

There is a statement: "Apple is the Anthem"

How do I write a step that finds the difference in positions between the two As?

THANK YOU!!!!

Accepted Solutions
Solution
‎04-11-2016 10:05 PM
Super User
Posts: 10,787

## Re: Difference in positions

Just two A ?

``````data _null_;
x="Apple is the Anthem";
a=findc(x,'A');
b=findc(x,'A','b');
dif=b-a;
put a= b= dif=;
run;``````

All Replies
Super User
Posts: 23,776

## Re: Difference in positions

Well, you could use the index function to find each A and then subtract but that doesn't scale well.

Will you always be looking for two As?

It looks like your doing string functions. You may want to review the available functions here

http://support.sas.com/documentation/cdl/en/lefunctionsref/67960/HTML/default/viewer.htm#p0w6napahk6...

Contributor
Posts: 21

## Re: Difference in positions

Hi Reesa,

I will review these! Thank you greatly !!
Solution
‎04-11-2016 10:05 PM
Super User
Posts: 10,787

## Re: Difference in positions

Just two A ?

``````data _null_;
x="Apple is the Anthem";
a=findc(x,'A');
b=findc(x,'A','b');
dif=b-a;
put a= b= dif=;
run;``````
Contributor
Posts: 21

## Re: Difference in positions

Hi Ksharp,

Works perfectly!

🔒 This topic is solved and locked.