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: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 12920 views
  • 2 likes
  • 4 in conversation