BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Ronein
Meteorite | Level 14

Hello

In proc sql i want to use in operator.

What is the correct way?

If there are some items ,should I use comma between them or also a space can work?

 

I run this example and both method worked 

 

Data tbl;
input ID  branch;
cards;
1 100
2 100
3 200
4 300
5 400
6 500
7 500
8 500
9 500
10 500
;
run;

PROC SQL;
	create table outcome as
	select *	   
	from tbl
	where branch in (100, 200, 300, 400, 500)
;
QUIT;

PROC SQL;
	create table outcome as
	select *	   
	from tbl
	where branch in (100  200  300  400  500)
;
QUIT;
1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Both methods are equal. I personally prefer commas in "in"-lists because I rarely use SQL and commas are needed in the when() conditions of select() blocks in data steps, where the in-lists often end up.

View solution in original post

3 REPLIES 3
Kurt_Bremser
Super User

Both methods are equal. I personally prefer commas in "in"-lists because I rarely use SQL and commas are needed in the when() conditions of select() blocks in data steps, where the in-lists often end up.

PeterClemmensen
Tourmaline | Level 20

They generate identical results, but IMO it is bad programming practice to omit the commas.

Tom
Super User Tom
Super User

That is one of the nicest features of SAS code, especially if you need to create macros that take in lists of values as parameters.

Commas are a pain to pass into macro calls because they are used to separate parameters.

%macro subset(in,out,var,list);
data &out;
 set ∈
 where &var in (&list);
run;
%mend subset;

proc sql noprint;
  select quote(trim(name)) into :mylist separated by ' '
    from sashelp.class
    where sex='F'
  ;
quit;

%subset(in=sashelp.class,out=females,var=name,list=&mylist);

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 3 replies
  • 13082 views
  • 2 likes
  • 4 in conversation