将时间戳转换为SAS宏变量
如何将时间戳转换为数值值,而无需微秒的值将其四舍五入并将其存储在宏变量中
data temp;
ts='2022-05-18:10:11:12.796429';
ts1 = input(ts,anydtdtm26.);
putlog 'ts1-->' ts1;
call symput('new_ts1',ts1);
run;
%put new_ts1: &new_ts1;
ts1-->1968487872.8
new_ts1: 1968487872.8
是否可以存储实际值而不是圆形值?
how to convert the timestamp into numeric value without microseconds value getting rounded up and store it in a macro variable
data temp;
ts='2022-05-18:10:11:12.796429';
ts1 = input(ts,anydtdtm26.);
putlog 'ts1-->' ts1;
call symput('new_ts1',ts1);
run;
%put new_ts1: &new_ts1;
ts1-->1968487872.8
new_ts1: 1968487872.8
Is it possible to store the actual value instead of the round value?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您一直在问同样的问题。
校正
否。将DateTime(又称时间戳)值存储到SAS中的Micro Second是不可能的。对于将小数点作为浮点数编号存储的小数值将超过精度的限制。
您可以将大量数字存储为整数的微秒数。但并不是以微秒为代表的秒数为秒。
示例:
请注意,在以秒数为单位存储时,微秒位置数字是如何丢失的,但是当存储为微秒的整数计数时,该值仍然存在。
不。您不能使用AnyDTDTM Informat将特定的字符串转换为具有微秒精度的DateTime值。使用其他方法。并将微秒存储在DateTime的单独变量中。
否。您不能使用隐式传递到DB2来移动DateTime值并将精度保留到Micro Second。
要将值从DB2移动到SAS,将它们转换为DB2中的字符串并移动字符串。然后,您可以使用上述方法在需要的情况下转换为实际的DateTime值。
要将值移回DB2,您可以逆转该过程并将值作为字符串移动,然后使用DB2代码将其转换为DB2时间戳值。或生成代码通过explicit Pass在DB2中运行(也许是通过将DB2时间戳的文本构建到宏变量中)将传递该值。
因此,也许类似:
您可以尝试构建这样的字符串,以使日期,时间和微秒片段串联。在将微秒转换为字符串时,请确保使用z格式,以便小于十分之一的值将具有所需的前导零。
因此
You keep asking this same question.
Correction
NO. It is impossible to store datetime (aka timestamp) values to the micro second in SAS. The values will exceed the limits of precision for storing decimal values with fractions as floating point numbers.
You can store that large a number as an integer number of microseconds. But not as a number of seconds with microseconds represented as fractions of a second.
Example:
Notice how the microseconds place digit is lost when stored in number of seconds but when stored as an integer count of microseconds instead the value is still there.
NO. You cannot use the ANYDTDTM informat to convert that specific string into a datetime value with microsecond precision. Use a different method. And store the microseconds in a separate variable from the datetime.
NO. You cannot use implicit passthru to DB2 to move datetime values and retain the precision to the micro second.
To move the values from DB2 to SAS convert them to a string in DB2 and move the string. You can then use a method like above to convert into an actual datetime value if you need.
To move the values back to DB2 you reverse the process and move the value as a string and use DB2 code to convert it to a DB2 timestamp value. Or generate code to run in DB2 via explicit pass thru (perhaps by building the text of a DB2 timestamp literal into a macro variable) that will transfer the value.
So perhaps something like:
You could try to build such a string be concatenating the date, time and microsecond pieces. Make sure the use the Z format when converting the microseconds into a string so that values less than a tenth of a second will have the needed leading zeros.
So if you want to generate a string like
'2022-05-18:10:11:12.796429'
you might do this: