BookmarkSubscribeRSS Feed
xxformat_com
Barite | Level 11

I was surprised to find out that the IN operator is not supported variable names.

If things change, just let me know

https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lepg/p1n8bsqqd03xppn17pgvjpjlbhhs.htm#n0bcs3v...

 


data demo;
    x=1;
run;

data demo1;
    set demo;
    if x in (1,2) then flag=1;
run;

data demo2;
    set demo;
    y=1;
    if x = y or x =2 then flag=1;
run;

data demo3;
    set demo;
    y=1;
    if x in (y,2) then flag=1;
run;
 ERROR 22-322: Syntax error, expecting one of the following: a quoted string, a numeric constant, a datetime constant, 
               a missing value, iterator, (.  
 
 ERROR 202-322: The option or parameter is not recognized and will be ignored.
2 REPLIES 2
FreelanceReinh
Jade | Level 19

The WHICHN/WHICHC functions provide a workaround in this situation:

if whichn(x,y,2) then flag=1;

 

The IN operator can also be applied to an array

if x in a then flag=1;

which, of course, must be defined earlier in the DATA step, e.g.:

array a[*] y z (1 2);

 

Ksharp
Super User

As Freelancer showed you ,you should use array operator:

 


data demo;
    x=1;
run;

data demo3;
    set demo;
	array _x y z ;
    y=1;z=2;
    if x in _x then flag=1;
run;

P.S. variable z and _x must be not exist in dataset demo.

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 288 views
  • 5 likes
  • 3 in conversation