Help using Base SAS procedures

Alternatives to Index(s1,s2)

Accepted Solution Solved
Reply
Contributor
Posts: 64
Accepted Solution

Alternatives to Index(s1,s2)

I'm having problems using INDEX() function ... 

I have a string variable which is a space separated list,

s = AGE WEIGHT GENDER HEIGHT

When I query a dataset like this:

proc sql;

  select variablename

  from MYDATASET

  where index("%upcase(%sysfunc(compbl(&s)))", compress(upcase(variablename), ' ')) > 0; quit;run;

I end up getting results like this:

WEIGHT

MAX_WEIGHT

MIN_WEIGHT

ANYTHING_WITH_WEIGHT_IN_IT

I'm looking for a perfect match by word - not pattern. I was thinking of appending a space to either end of the search pattern, but I'm not sure if that's the most elegant


Accepted Solutions
Solution
‎06-10-2014 07:36 PM
Super User
Posts: 19,876

Re: Alternatives to Index(s1,s2)

IndexW - index word function

Also, you can use the upcase/upper and compbl function directly, you don't need % or sysfunc as far as I can see.

View solution in original post


All Replies
Solution
‎06-10-2014 07:36 PM
Super User
Posts: 19,876

Re: Alternatives to Index(s1,s2)

IndexW - index word function

Also, you can use the upcase/upper and compbl function directly, you don't need % or sysfunc as far as I can see.

Contributor
Posts: 64

Re: Alternatives to Index(s1,s2)

Many thanks! That's exactly what I was looking for.

🔒 This topic is solved and locked.

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

Discussion stats
  • 2 replies
  • 184 views
  • 1 like
  • 2 in conversation