cancel
Turn on suggestions
Showing results for
Search instead for
Did you mean:
BookmarkSubscribeRSS Feed
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.
0 Likes
2 REPLIES 2
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);
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.

0 Likes

sasinnovate.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just 495ドル!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
[フレーム]

AltStyle によって変換されたページ (->オリジナル) /