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: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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