如何解决SAS proc sql passthrough无限期运行
我有一些周-日期-时间格式的数据,即 14dec2020:00:00:00:000。我正在使用 SAS 和 proc sql (SQL Server) 传递查询
此数据包含数周的数据,但我很好奇是否可以仅提取与当前周相关的数据? 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 $22;
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;
宏数据集返回正确的日期边界,但当它尝试运行 PROC SQL 时,它会无限期地运行。我运行了 16 分钟,它的 CPU 运行时间只有 1.09 秒。我已尝试将 cstart
和 cend
更改为在整个查询过程中仅开始和结束,但没有匹配。
这里的任何帮助将不胜感激!
解决方法
此示例代码将记录 SAS 生成的传递查询是什么。尝试使用 SQL Server 工具执行相同的查询。
%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,"'"));
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;
日志窗口
MPRINT(QUERY): create table work.pleasehelp as select * from connection to odbc (
select Year,SKU from datatable where '2020-12-27' <= Week and Week < '2021-01-03'
order by SKU
);
NOTE: Statement not executed due to NOEXEC option.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。