BookmarkSubscribeRSS Feed
deleted_user
Not applicable
I'm trying to work around the Oracle 1,000 item limit for an IN statement and want to dynamically create multiple in statements of 1,000 (or less) items separated by an OR.
I have a table containing a field called gpi_nbr among other fields. There are currently a total of 4,623 rows in this table. I will pull a subset of rows from this table by filtering on one or more of the other fields. In one case I will pull 2,500 rows. So I need to create 3 lists, two containing 1,000 gpi_nbr and the third containing the remaining 500 gpi_nbr.
These lists will be used to query another dataset with a filter like...
...
and (gpi_nbr in (&list1) or gpi_nbr in (&list2) or gpi_nbr in (&list3))
...

I've been able to create a single list using the following code...

proc sql noprint;
select '"'||gpi_nbr||'"'
into :varlist separated by ','
from WH_TEMP;
quit;

%let cntlist = &sqlobs;
%let nbrlists = %sysevalf(&cntlist/1000, ceil);
%put &cntlist;
%put &nbrlists;
%put &varlist;

cntlist tells me how many rows I am returning
nbrlists tells me how many lists i need to create

I'm relatively new to sas coding and just can't figure out what to do next. I know I need to do something n times (in this case n=3=nbrlists).
3 REPLIES 3
Flip
Fluorite | Level 6
Wouldn't it be simpler to use a subquery for your IN statement? Or an EXISTS?
deleted_user
Not applicable
Most often the list data will come from a different database than the data I want to filter. It was my understanding that if you cross databases, the entire dataset would be pulled down to the sas server before the subquery would be applied. When looking at a years worth of data I'm in the 21-30 million record range. Is that correct? If not, I'd be thrilled to handle this using sql.
Flip
Fluorite | Level 6
Let ORACLE do the work. Run it as a passthrough. If the lookup table is in SAS create a temporary table in ORACLE and do the subsetting there like

create table big as select * from connection to oracle (select .....
.. where var in (select var from temptable));

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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
  • 670 views
  • 0 likes
  • 2 in conversation