将DB2时间戳转换为SAS数字
我想将DB2时间戳转换为SAS数字
proc sql;
connect to db2 ;
create table db2ts as
select * from connection to db2
(select char(current timestamp)
from sysibm.sysdummy1)
as db2ts(timestm);
%put &sqlxmsg ;
%put &sqlxrc ;
disconnect from db2;
quit;
data _NULL_;
set DB2TS;
putlog 'timestmb--' timestm;
datets =input(timestm,yymmdd10.);
timets =input(substr(timestm,12),time15.);
dt2=dhms(datets,0,0,timets);
format datets date9. timets time15.6 dt2 datetime26.6;
putlog 'currdatets:' dt2;
call symput('currdatets',catx('-',put(datepart(dt2),yymmdd10.),
translate(put(dt2,tod15.6),'.',':')));
putlog 'currdatets:' currdatets;
run;
timestmb--2022-05-18-16.44.54.587001
currdatets:18MAY2022:16:44:54.587001
%put currdatets: &currdatets;
currdatets: 2022-05-18-16.44.54.587001
Proc sql:
Insert into table1
(Time, Type)
Values
(%sysfunc(quote(&currdatets)), 'A')
错误:
错误:值第1条的值1不匹配
对象项目列表中相应列的数据类型(在“选择”子句中)。
如何使用宏变量Currdatet插入DB2表中?
I want to convert the Db2 timestamp into SAS numeric
proc sql;
connect to db2 ;
create table db2ts as
select * from connection to db2
(select char(current timestamp)
from sysibm.sysdummy1)
as db2ts(timestm);
%put &sqlxmsg ;
%put &sqlxrc ;
disconnect from db2;
quit;
data _NULL_;
set DB2TS;
putlog 'timestmb--' timestm;
datets =input(timestm,yymmdd10.);
timets =input(substr(timestm,12),time15.);
dt2=dhms(datets,0,0,timets);
format datets date9. timets time15.6 dt2 datetime26.6;
putlog 'currdatets:' dt2;
call symput('currdatets',catx('-',put(datepart(dt2),yymmdd10.),
translate(put(dt2,tod15.6),'.',':')));
putlog 'currdatets:' currdatets;
run;
timestmb--2022-05-18-16.44.54.587001
currdatets:18MAY2022:16:44:54.587001
%put currdatets: &currdatets;
currdatets: 2022-05-18-16.44.54.587001
Proc sql:
Insert into table1
(Time, Type)
Values
(%sysfunc(quote(&currdatets)), 'A')
Error:
ERROR: Value 1 of VALUES clause 1 does not match the data type of
the corresponding column in the object-item list(in the SELECT clause).
how can I use the macro variable currdatets to insert into the DB2 table?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因此,您的第一个查询不是有效的SQL语法,因此我不确定它是如何工作的。尝试类似的内容:
这将创建一个数据集名称
db2ts
,其中一个名为timestmp
的字符变量;这应该与您通过此数据步骤获得的相似。
现在,您可以将字符串转换为日期和时间值,然后将其组合到DateTime值。
结果:
如果您可以弄清楚DB2是否具有cast()函数的函数或选项,可以让您指定字符串是如何生成的,以便SAS可以立即识别为DateTime的东西,这将变得更容易。
So your first query is not valid SQL syntax so I am not sure how it even works. Try something like:
This will create a dataset name
db2ts
with a character variable namedtimestmp
;Which should be the similar to what you would get with this data step.
Now you can convert the string into a DATETIME value by first converting it into a DATE and a TIME value and then combining them.
Results:
It would be easier if you could figured out if DB2 has a function, or option for the CAST() function, that can let you specify how the string is generated so that it is something that SAS can recognize immediately as a datetime.