BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sasuser123123
Quartz | Level 8
Hello!!
I've a date which is in character value is 20110423 and time 0015(character)
Now I'm trying to concatenate these two variables but error is coming
Could you please tell me how to get the new variable which consists date and time in datetime format

Thank you!!
1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

The B8601DT informat should be able to do that. Just stick the letter T between the data and time strings.

data test;
  date='20110423';
  time='0015';
  datetime=input(catx('T',date,time),b8601dt.);
  format datetime datetime20.;
run;

View solution in original post

3 REPLIES 3
novinosrin
Tourmaline | Level 20

Hi @sasuser123123 

 

data want;
d="20110423";
d1=input(d,yymmdd10.);
t="0015";
t1=input(substr(t,1,2)||':'||substr(t,3),hhmmss.);
datetime=dhms(d1,0,0,0)+t1;
format datetime datetime20.;
drop d1 t1;
run;
Tom
Super User Tom
Super User

The B8601DT informat should be able to do that. Just stick the letter T between the data and time strings.

data test;
  date='20110423';
  time='0015';
  datetime=input(catx('T',date,time),b8601dt.);
  format datetime datetime20.;
run;
sasuser123123
Quartz | Level 8
It's perfectly working. Thank you so much for your assistance
And could you please explain a little about B8601DT informat why we use that informat here.

Thank you.!

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 connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 1772 views
  • 2 likes
  • 3 in conversation