samrat
samrat

Reputation: 43

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=&timestampcur.;

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

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

%put Y=&Y.;

Output: 

Y = "AT" || 335491

Upvotes: 0

Views: 208

Answers (3)

Richard
Richard

Reputation: 27498

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;

Upvotes: 1

Dirk Horsten
Dirk Horsten

Reputation: 3845

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;

Upvotes: 1

Tom
Tom

Reputation: 51566

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.

Upvotes: 1

Related Questions