Index/find with punctuation

Accepted Solution Solved
Reply
Contributor
Posts: 44
Accepted Solution

Index/find with punctuation

Hello SAS Community,

Based on the sample data below, I would like to use a character function (index/find) to subset the observations where VariableB is not in Variable A (on either side of the |).

Could anyone please suggest code for doing this for the whole dataset? I tried "proc print; where find(VariableA,VariableB) = 0; run;" but this doesn't work.

VariableA VariableB

AA|CC     AA

AA|CC     CC

AC|AA     CC

......

Thank you.


Accepted Solutions
Solution
‎05-21-2014 09:11 AM
Super User
Posts: 9,691

Re: Index/find with punctuation

There is a pitfall of trailing blank when you use find() index() with a variable. You should use strip() or trim() to cut off the trailing blanks of that variable.

data have;
input VariableA $ VariableB     $ ;
cards;
AA|CC     AA
AA|CC     CC
AC|AA     CC
;
run;
data have;
 set have;
 a=find(VariableA,strip(VariableB));
run;

Xia Keshan

View solution in original post


All Replies
Respected Advisor
Posts: 3,124

Re: Index/find with punctuation

I would feel bad if I throw out an answer for a homework assignment. How about a hint: find/index do not work with most of the Procs ( in your case, you choose proc print), and proc print will NOT subset tables, it will just print like its name implied. Have you tried to use Date Step?

Regards,

Haikuo

Solution
‎05-21-2014 09:11 AM
Super User
Posts: 9,691

Re: Index/find with punctuation

There is a pitfall of trailing blank when you use find() index() with a variable. You should use strip() or trim() to cut off the trailing blanks of that variable.

data have;
input VariableA $ VariableB     $ ;
cards;
AA|CC     AA
AA|CC     CC
AC|AA     CC
;
run;
data have;
 set have;
 a=find(VariableA,strip(VariableB));
run;

Xia Keshan

Respected Advisor
Posts: 3,777

Re: Index/find with punctuation

RTM FIND has options.

find(VariableA,VariableB,'T')
Super User
Posts: 9,691

Re: Index/find with punctuation

Yeah . Both same . if there are some leading blanks ? :smileyblush:

Regards.

Xia Keshan

Respected Advisor
Posts: 3,777

Re: Index/find with punctuation

Look in the book. :smileyplain:

🔒 This topic is solved and locked.

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

Discussion stats
  • 5 replies
  • 263 views
  • 2 likes
  • 4 in conversation