DATA Step, Macro, Functions and more

SYSDATE and SYSTIME

Accepted Solution Solved
Reply
Regular Contributor
Posts: 215
Accepted Solution

SYSDATE and SYSTIME

Hi All,

I am trying to concatenate some character variables and one of those variable is SYS date and time. SYS date and time should be YYYY-MM-DD:hh:mm:ss format. Can someone help me please. Thanks.

 

The code i am trying to write is like:

 

DATA test;
Long_char='1234'||'ABCD'||System date and Time;
RUN;

 

Expected output:

Long_char=1234ABCD2016-02-09:15:41:29


Accepted Solutions
Solution
‎05-27-2016 12:14 PM
Super User
Posts: 5,260

Re: SYSDATE and SYSTIME

Long_char="&long_char";
Data never sleeps

View solution in original post


All Replies
Super User
Posts: 17,912

Re: SYSDATE and SYSTIME

[ Edited ]

You can use datetime() function instead. My personal preference is to use the CATT function, I find it more readable.

 

%put %sysfunc(datetime(), datetime21.);

data want;
long_var = catt("1234", "ABCD", put(datetime(), datetime21.));
run;

proc print data=want;
run;

 

Regular Contributor
Posts: 215

Re: SYSDATE and SYSTIME

Hi Reeza,
Thank you for the solution, but your code leave three spaces between third character and the date. Also it doesn't show (-) in between (like YYYY-MM-DD). I want it like 2016-02-09:15:41:29. can you please help further. Thanks.

%put %sysfunc(datetime(), datetime21.);

DATA have;
long_char='T1'||'12345'||'000000000000'||put(datetime(), datetime21.);
RUN;
Super User
Posts: 5,260

Re: SYSDATE and SYSTIME

%Let long_char=1233ABCD%sysfunc(today(),yymmdd10.):%sysfunc(time(),time.);
Data never sleeps
Regular Contributor
Posts: 215

Re: SYSDATE and SYSTIME

[ Edited ]

Hi LinusH,
Thank for your code, but I don't know how to put it in the data step. Would you please put your code in the following data step so that I can get my expected result. I never worked with a let statement. Thanks.

 

DATA have;
long_char='1234'||'ABCD'||SYS date and SYS time;
RUN;

 

Expected output:

long_char=1234ABCD2016-02-09:15:41:29

Solution
‎05-27-2016 12:14 PM
Super User
Posts: 5,260

Re: SYSDATE and SYSTIME

Long_char="&long_char";
Data never sleeps
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 707 views
  • 2 likes
  • 3 in conversation