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

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
WarrenKuhfeld
Rhodochrosite | Level 12

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

3 REPLIES 3
WarrenKuhfeld
Rhodochrosite | Level 12

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?

Tom
Super User Tom
Super User

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.

 

hhchenfx
Barite | Level 11

My bad. I am sorry.

HHC

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 3 replies
  • 620 views
  • 1 like
  • 3 in conversation