DATA Step, Macro, Functions and more

Index() function pick up unnecessary records

Accepted Solution Solved
Reply
Super Contributor
Posts: 503
Accepted Solution

Index() function pick up unnecessary records

Hi Everyone,

I have a quick question. When I run the 

 

if index(project,"VI SP - OH")>0 then output;

SAS pick up also record such as "014 VI SP" which clearly have no "- OH" component.

 

 

Can you fix my code so it strictly pick only those containing "VI SP - OH" ?

 

Thank you,

 

HHC

 


Accepted Solutions
Solution
‎11-07-2017 12:13 PM
SAS Super FREQ
Posts: 497

Re: Index() function pick up unnecessary records

The INDEX function works correctly.  Double check your data and the rest of the logic in your program.  Are you outputting other records by using another OUTPUT statement?

View solution in original post


All Replies
Solution
‎11-07-2017 12:13 PM
SAS Super FREQ
Posts: 497

Re: Index() function pick up unnecessary records

The INDEX function works correctly.  Double check your data and the rest of the logic in your program.  Are you outputting other records by using another OUTPUT statement?

Super User
Super User
Posts: 7,932

Re: Index() function pick up unnecessary records

[ Edited ]

Something else is your issue.

The INDEX function will not match strings that are not exactly the same.

574   data test;
575    input project $70. ;
576    found=index(project,"VI SP - OH");
577    put found= project=$quote. ;
578   cards;

found=0 project="014 VI SP which clearly have no ""- OH"" component."
found=5 project="015 VI SP - OH"
NOTE: The data set WORK.TEST has 2 observations and 2 variables.

 

Super Contributor
Posts: 503

Re: Index() function pick up unnecessary records

My bad. I am sorry.

HHC

☑ This topic is solved.

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

Discussion stats
  • 3 replies
  • 100 views
  • 1 like
  • 3 in conversation