SAS proc sql 直通 运行 无限期
SAS proc sql passthrough running indefinitely
我有一些周-日期-时间格式的数据,即 14dec2020:00:00:00:000。我正在使用 SAS 和一个 proc sql (SQL 服务器) 通过查询
此数据包含许多周的数据,但我很好奇是否有办法只提取与本周相关的数据? IE 今天是 17dec2020,所以我只想提取 14dec2020 那一周的数据。如果今天是 2020 年 12 月 22 日,那么我希望它提取 2020 年 12 月 21 日这一周的数据。
Data macros;
today = today();
wkday = weekday(today);
start = today()-(wkday-1);
end = today+(7-wkday);
length cstart cend ;
cstart = "'" || put(start, date9.) || ':00:00:00.000' || "'";
cend = "'" || put(end, date9.) || ':00:00:00.000' || "'";
call symput ('start', cstart);
call symput('end', cend);
run;
proc sql;
connect to odbc (dsn='x' uid='y' pwd='z');
create table work.pleasehelp as select * from connection to odbc
(select Year, Month, Week, store, sales, SKU
from datatable
Where (&start. <= Week and week <= &end.)
order by SKU);
disconnect from odbc;
quit;
有宏数据设置 returns 正确的日期边界,但当它尝试 运行 处理 PROC SQL 时,它 运行 无限期。我 运行 它持续了 16 分钟,它只有 CPU 运行 1.09 秒的时间。我已经尝试将 cstart
和 cend
更改为仅在整个查询中开始和结束,但是 运行 没有匹配项。
如有任何帮助,我们将不胜感激!
此示例代码将记录 SAS 生成的传递查询是什么。尝试执行相同的查询是一个 SQL 服务器工具。
%let start=;
%let end=;
data _null_;
last_sunday = intnx('week', today(), 0);
next_sunday = last_sunday + 7;
call symput('last_sunday', quote(put(last_sunday, yymmdd10.),"'"));
call symput('next_sunday', quote(put(next_sunday, yymmdd10.),"'"));
run;
/* The source code in the macro variables is
'yyyy-mm-dd'
and will be understood by SQL Server to be an ISO8601 standard date value
*/
%put &=last_sunday;
%put &=next_sunday;
/* This macro has SQL NOEXEC so you can see in the LOG window what
the pass through query is. Try running the same query in a
SQL Server tool to see what the expected result set is
*/
%macro query;
proc sql noexec;
connect to odbc (dsn=x uid=y pwd=z);
create table work.pleasehelp as
select * from connection to odbc
( select Year, Month, Week, store, sales, SKU
from datatable
where &last_sunday <= Week and Week < &next_sunday
order by SKU
);
disconnect from odbc;
quit;
%mend;
options mprint;
%query;
日志window
MPRINT(QUERY): create table work.pleasehelp as select * from connection to odbc (
select Year,
Month, Week, store, sales, SKU from datatable where '2020-12-27' <= Week and Week < '2021-01-03'
order by SKU
);
NOTE: Statement not executed due to NOEXEC option.
我有一些周-日期-时间格式的数据,即 14dec2020:00:00:00:000。我正在使用 SAS 和一个 proc sql (SQL 服务器) 通过查询
此数据包含许多周的数据,但我很好奇是否有办法只提取与本周相关的数据? IE 今天是 17dec2020,所以我只想提取 14dec2020 那一周的数据。如果今天是 2020 年 12 月 22 日,那么我希望它提取 2020 年 12 月 21 日这一周的数据。
Data macros;
today = today();
wkday = weekday(today);
start = today()-(wkday-1);
end = today+(7-wkday);
length cstart cend ;
cstart = "'" || put(start, date9.) || ':00:00:00.000' || "'";
cend = "'" || put(end, date9.) || ':00:00:00.000' || "'";
call symput ('start', cstart);
call symput('end', cend);
run;
proc sql;
connect to odbc (dsn='x' uid='y' pwd='z');
create table work.pleasehelp as select * from connection to odbc
(select Year, Month, Week, store, sales, SKU
from datatable
Where (&start. <= Week and week <= &end.)
order by SKU);
disconnect from odbc;
quit;
有宏数据设置 returns 正确的日期边界,但当它尝试 运行 处理 PROC SQL 时,它 运行 无限期。我 运行 它持续了 16 分钟,它只有 CPU 运行 1.09 秒的时间。我已经尝试将 cstart
和 cend
更改为仅在整个查询中开始和结束,但是 运行 没有匹配项。
如有任何帮助,我们将不胜感激!
此示例代码将记录 SAS 生成的传递查询是什么。尝试执行相同的查询是一个 SQL 服务器工具。
%let start=;
%let end=;
data _null_;
last_sunday = intnx('week', today(), 0);
next_sunday = last_sunday + 7;
call symput('last_sunday', quote(put(last_sunday, yymmdd10.),"'"));
call symput('next_sunday', quote(put(next_sunday, yymmdd10.),"'"));
run;
/* The source code in the macro variables is
'yyyy-mm-dd'
and will be understood by SQL Server to be an ISO8601 standard date value
*/
%put &=last_sunday;
%put &=next_sunday;
/* This macro has SQL NOEXEC so you can see in the LOG window what
the pass through query is. Try running the same query in a
SQL Server tool to see what the expected result set is
*/
%macro query;
proc sql noexec;
connect to odbc (dsn=x uid=y pwd=z);
create table work.pleasehelp as
select * from connection to odbc
( select Year, Month, Week, store, sales, SKU
from datatable
where &last_sunday <= Week and Week < &next_sunday
order by SKU
);
disconnect from odbc;
quit;
%mend;
options mprint;
%query;
日志window
MPRINT(QUERY): create table work.pleasehelp as select * from connection to odbc (
select Year,
Month, Week, store, sales, SKU from datatable where '2020-12-27' <= Week and Week < '2021-01-03'
order by SKU
);
NOTE: Statement not executed due to NOEXEC option.