can't write 'contains' in the if expression?

Reply
Occasional Contributor
Posts: 5

can't write 'contains' in the if expression?

Can I write ? or contains instead of = in the if then loop?

data orion.comp;

    set orion.sales;

    if job_title = 'Sales Rep. IV' then

        bonus=1000;

    /*if job_title ? 'Sales Manager' then

        bonus=1500;expression,

    if job_title ? 'Senior' then

        bonus=2000;

    if job_title ? 'Chief' then

        bonus=2500;*/

run;

Respected Advisor
Posts: 3,788

Re: can't write 'contains' in the if expression?

Have a look at the FIND and FINDW functions.

Valued Guide
Posts: 2,177

Re: can't write 'contains' in the if expression?

ricodonself wrote:

Can I write ? or contains instead of = in the if then loop?

code updated replacing ? operators

data orion.comp;

    set orion.sales;

    if job_title = 'Sales Rep. IV' then

        bonus=1000;

      if find( job_title, 'Sales Manager', 'i' ) then

        bonus=1500;

else

    if  find( job_title, 'Senior', 'i') then

        bonus=2000;

else

    if find( job_title, 'Chief', 'i' ) then

        bonus=2500;

run;

Trusted Advisor
Posts: 1,228

Re: can't write 'contains' in the if expression?

We can't use contains in if statement. As an alternate you can try something like this.

if index(job_title,'Sales Rep. IV')  then

bonus=1000;

Super User
Posts: 11,134

Re: can't write 'contains' in the if expression?

"Contains" is pretty much restricted to Proc SQL in SAS.

Ask a Question
Discussion stats
  • 4 replies
  • 295 views
  • 10 likes
  • 5 in conversation