如何在 SAS 中使用对 Oracle 的 SQL 直通查询一次循环 1000 条记录

问题描述 投票:0回答:2

由于 Oracle 中的数据读取有 1000 条记录限制,我如何从 SAS 数据集中一次读取 1000 行,以便我可以创建一个宏变量列表以传递给 SAS SQL 直通查询

oracle variables sas macros
2个回答
0
投票
Create a SAS macro that will read the data in chunks and generate a macro 
variable list.
%macro create_macro_var_list(dataset_name, chunk_size, out_macro_var);
    data _null_;
        set &dataset_name;
        if _n_ = 1 then call symputx("&out_macro_var", "", "G");
        if mod(_n_, &chunk_size) = 1 then do;
            if _n_ > 1 then call symputx("&out_macro_var", 
"&out_macro_var.", "G");
            call symputx("&out_macro_var", catx(",", &out_macro_var, _n_), 
"G");
        end;
       if eof then call symputx("&out_macro_var", "&out_macro_var.", "G");
   run;
%mend;

/* Define your SQL query with the macro variable */
%let id_list = &id_list;
%let sql_query = 
    SELECT *
    FROM your_oracle_table
    WHERE rownum in (&id_list);

/* Execute the SQL Pass-thru Query */
PROC SQL;
    CONNECT TO ORACLE AS ORADB (your_connection_details);
    CREATE TABLE work.temp_table AS
    SELECT *
    FROM CONNECTION TO ORADB
    (
        &sql_query
    );
    DISCONNECT FROM ORADB;
QUIT;

0
投票

使用 CALL EXECUTE 或 DOSUBL 以 ID 作为数据源的数据集生成所需的完整查询。请参阅下面的示例。

data list_ages;
input age;
cards;
10
14
15
16
;;;;
run;


data _null_;
set list_ages end=eof;

if _n_=1 then do;
call execute('proc sql; create table want as select * from sashelp.class where age in (');
end;

call execute(age);
if not eof then call execute(' , ');

if eof then call execute(');quit');

run;
© www.soinside.com 2019 - 2024. All rights reserved.