BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Astounding
PROC Star

hsharmas,

While it wouldn't hurt to check the values stored in BRAND_NAME1, I'm going to assume that those are correct.  Most likely, the problem lies with your use of KINDEX (same would apply to the INDEX function).  The second parameter, the string to search for, should be modified:

strip(target_brand{i})

As it stands now, the string being searched for is 30 characters long:  "VIKING" plus 24 additional blanks.  The STRIP function will remove leading and trailing blanks, and let you search for just the six characters "VIKING".

Good luck.

...

Sorry, Vince.  I was lazy and didn't read all the previous answers as carefully as I should have  You had already mentioned TRIM, which should work just as well as STRIP in this case.  At any rate, I had posted a bit of explanation as to why it's needed.

hsharmas
Fluorite | Level 6

Hi Scott, Vince, Reeza

Thanks for the info. I just wonder including the TRIM function in the index function makes such a difference when I already had a variable using STRIP func including in the array. Anyways can anybody tell me about if you have a case of :

Keyword: RANERIS ERIS and Lookupvalue: ERIS

I want the function to return me back the second ERIS word. I though adding the space in the starting of the word will help but SAS does not take care of it.

I am confused how to do it where I get the position of the exact word and not the word that is part of other word.

Thanks

Vince28_Statcan
Quartz | Level 8

Hi hsharmas,

The reason you need trim again in the kindex function is because when you stripped blanks when you created your array, SAS still naturally blank-padded the resulting stripped value to "fill" the length $30. of each array bucket. So when you use array index, it still returns a 30 length string with zero padding.

For the RANERIS vs ERIS issue. If you ought to stick to the array method, you will want to use findw() function instead of kindex which has natural handling of words. The backdraw is if you have dictionary entries that are like "Mega Corp" because then it can't ever match any single word delimited by findw().

Similarly, you can use the scan()/hash lookup method discussed in the other similar thread I linked on these forums.

If you have multi word dictionary entries like the mega corp above, you would probably need to use PERL to indicate that you must have a nonletter preceeding and following the match. Since PERL syntax is not trivial and you may very well not need it, I'll leave it to you to see if findw() function is sufficient for your requirements.

There are probably plenty of other ways like conditioning on a blank space at substr(keyword3, bb-1, 1)=" " but the issue with this is that you then need to consider for if the match is the first word of the string for example.

Astounding
PROC Star

One of the standard techniques for dealing with the RANERIS vs. ERIS situation is to pad both parameters with a leading and trailing blank.  It becomes mildly clumsy:

bb = kindex(" " || keyword3 || " ", " " || trim(target_brand{i}) || " ");


hsharmas
Fluorite | Level 6

Astounding:  Thanks a lot ,If that works for me. I will let you know in 15 mins from now!

hsharmas
Fluorite | Level 6

Astounding: It does work and that helps a lot!...Thanks Vince for explaining the difference. #Difference in variable values when using functions.

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
  • 20 replies
  • 1858 views
  • 8 likes
  • 5 in conversation