- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
They generate identical results, but IMO it is bad programming practice to omit the commas.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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);