这就是我目前面临的问题。我很难将SAS日期时间转换为SQL日期时间。
SAS Datetime中的显示值是28Mar2018:10:01:06,在执行Proc SQL时实际上是"28Mar2018:10:01:96"dt。
显示值为SQL Datetime is 2018-03-28 10:01:06.000,使用SQL Pass through时实际为'2018-03-28 10:01:06.000‘。
我有SAS日期时间值,并希望在SQL Pass直通语句中使用它。我一直在网上查找,但我找不到任何相关的信息。我最多只能找到转换日期。
直通语句应如下所示(不带connect to xxx语句)
%let sasdatetime=2018-03-28 10:01:06.000;
/*How to convert the value above to SQL format and apply in proc sql below*/
Proc sql:
connect to xxx
select *
from table A
where birthdatetime = &thedatetime;寻求您的忠告。
发布于 2018-03-09 10:03:00
下面是SAS直通到Teradata的示例。您可以对所需的数据库进行更改:
%let sasdatetime=2018-03-28 10:01:06.000;
%let tdlogin=%unquote(user=yourDBUsrNm pwd=yourDBPassWord MODE=Teradata tdpid=servername);
PROC SQL;
connect to teradata( &tdlogin connection = global);
CREATE TABLE work.test1 AS
SELECT * from connection to teradata
( select *
from table A
where birthdatetime = compress("'"||put(&sasdatetime,yymmddn8.)||"'")
);
disconnect from teradata;
QUIT;发布于 2018-03-09 11:00:26
您的查询称为显式SQL pass through,您可以使用connect语句将连接到数据库。在explcit pass through中,您必须遵守特定数据库的规则(不能使用SAS的任何组件),但是显式SQL pass through只允许您使用宏变量。
在各种数据库中,通常访问日期或日期时间如下所示,这与我们在SAS中访问日期的方式非常不同
where datecolumn = '2018-03-28'如下所示使用宏变量和在单引号中使用的问题是,在大多数数据库中,用于指示列名的单引号和双引号不能解析宏变量,因此宏变量上的单引号和双引号都不起作用
where datecolumn = '¯ovariable'一种解决方法是定义宏变量,然后使用%bquote,如下所示。
%let sasdatetime=2018-03-28 10:01:06.000;
Proc sql:
connect to xxx
select *
from table A
where birthdatetime = %bquote('&sasdatetime') ;另一种方法是在定义宏变量时使用单引号,然后在查询中不使用引号,如下所示。
%let sasdatetime='2018-03-28 10:01:06.000';
Proc sql:
connect to xxx
select *
from table A
where birthdatetime = &sasdatetime ;https://stackoverflow.com/questions/49185380
复制相似问题