SAS连接变量

发布于 2025-01-26 06:08:33 字数 408 浏览 2 评论 0原文

我想与从当前时间戳检索的微秒连接一个字符串“ AT”,但它无法正常工作。我可以得到一些帮助吗?

proc sql;

select * into :timestampcur
from connection to db2
(select char(CURRENT TIMESTAMP)
 from sysibm.sysdummy1
);
quit;

%put current_timestamp=&timestampcur.;

%let X =
     %sysfunc(compress ( %sysfunc(substr(&current_timestamp.,21,6))));

%let Y = "AT" || &X.;

%put Y=&Y.;

Output: 

Y = "AT" || 335491

I want to concatenate a string "AT" with the microseconds retrieved from the current timestamp, but it s not working as expected. Can i get some help please?

proc sql;

select * into :timestampcur
from connection to db2
(select char(CURRENT TIMESTAMP)
 from sysibm.sysdummy1
);
quit;

%put current_timestamp=×tampcur.;

%let X =
     %sysfunc(compress ( %sysfunc(substr(¤t_timestamp.,21,6))));

%let Y = "AT" || &X.;

%put Y=&Y.;

Output: 

Y = "AT" || 335491

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

黑白记忆 2025-02-02 06:08:33

如果您只是谈论将字符串存储到宏变量中,则只需从代码中删除不需要的字符即可。

%let Y=AT&X.;

请注意,您的代码似乎假设DB2表达式

char(CURRENT TIMESTAMP)

将返回一个至少26个字节长的字符串,而没有任何领先空间,并且字节21-26是代表毫秒的数字。

If you are talking about just storing the string into a macro variable then just remove the unneeded characters from your code.

%let Y=AT&X.;

Note that your code seems to be assuming that the DB2 expression

char(CURRENT TIMESTAMP)

will return a string that is at least 26 bytes long without any leading spaces and that the bytes 21-26 are the digits that represent milliseconds.

水晶透心 2025-02-02 06:08:33

为什么不首先创建两个大型载体呢?

proc sql;
select timestampcur, compress(substr(timestampcur,21,6))
into :timestampcur, :Y
from connection to db2
(select char(CURRENT TIMESTAMP) as timestampcur
 from sysibm.sysdummy1
);
quit;

Why not create two macrovariables in the first place?

proc sql;
select timestampcur, compress(substr(timestampcur,21,6))
into :timestampcur, :Y
from connection to db2
(select char(CURRENT TIMESTAMP) as timestampcur
 from sysibm.sysdummy1
);
quit;
南冥有猫 2025-02-02 06:08:33

DB2中的时间戳值将作为SAS DateTime值返回,该值是Epoch 01Jan1960:00:00:00:00:00:00:00:00:00。

proc sql;
  select (ts-int(ts)) * 1e6 into :db2_timestamp_msportion
  from connection to db2
  ( select CURRENT TIMESTAMP as ts from sysibm.sysdummy1 )
;
quit;

A TIMESTAMP value in DB2 will be returned as a SAS datetime value, which is decimal seconds from epoch 01jan1960:00:00:00.

proc sql;
  select (ts-int(ts)) * 1e6 into :db2_timestamp_msportion
  from connection to db2
  ( select CURRENT TIMESTAMP as ts from sysibm.sysdummy1 )
;
quit;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文