BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mlogan
Lapis Lazuli | Level 10

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

1 ACCEPTED SOLUTION

Accepted Solutions
LinusH
Tourmaline | Level 20
Long_char="&long_char";
Data never sleeps

View solution in original post

5 REPLIES 5
Reeza
Super User

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;

 

mlogan
Lapis Lazuli | Level 10
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;
LinusH
Tourmaline | Level 20
%Let long_char=1233ABCD%sysfunc(today(),yymmdd10.):%sysfunc(time(),time.);
Data never sleeps
mlogan
Lapis Lazuli | Level 10

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

LinusH
Tourmaline | Level 20
Long_char="&long_char";
Data never sleeps

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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