'SAS Concatenate variable
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
Solution 1:[1]
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.
Solution 2:[2]
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;
Solution 3:[3]
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;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Dirk Horsten |
| Solution 3 | Richard |
