Difference in positions

Accepted Solution Solved
Reply
Contributor
Posts: 21
Accepted Solution

Difference in positions

 Hello Smiley Happy

 

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,035

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;

View solution in original post


All Replies
Super User
Posts: 19,822

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,035

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!

 

Thank you for your sharp advice Smiley Happy

 

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 314 views
  • 2 likes
  • 3 in conversation