BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Mixer
Obsidian | Level 7

Hi All,

 

I am very new to SAS and try to learn the syntax. Sorry for my very basic question. I have below syntax and I think it's time addition but not certain.

 

((input(compress(substr(add_datetime,1,10),'-'),yymmdd8.))*86400)
+

(input(substr(add_datetime,12,8),TIME8.)) as add_datetime,

 

If I understand it correctly, it takes 10 characters from first position on the left of add_datetime, remove the dashes with compress function, convert to yymmdd8 format, convert to numeric/number of days with input function, then convert to seconds.

 

Plus/Concatenate

 

Second syntax is similar to above but extract time from add_datetime, convert to time8 format.

 

This is time addition syntax, correct?

 

Thank you for your answer.

 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

Your logic is indeed correct, but whether it will produce what you want will be dependent upon how the date variable was actually entered. Here's an example using your code and a slightly different date format based on today's datetime:

 

data test;
  format want datetime21.;
  add_datetime=catt(put(today(),mmddyyd10.),':',put(time(),time8.));
  want=((input(compress(substr(add_datetime,1,10),'-'),mmddyy8.))*86400) 
  +
  (input(substr(add_datetime,12,8),TIME8.));
run;

Art, CEO, AnalystFinder.com

 

View solution in original post

2 REPLIES 2
collinelliot
Barite | Level 11

My guess is you're making this way too complicated. Can you give an example of what add_datetime looks like?

art297
Opal | Level 21

Your logic is indeed correct, but whether it will produce what you want will be dependent upon how the date variable was actually entered. Here's an example using your code and a slightly different date format based on today's datetime:

 

data test;
  format want datetime21.;
  add_datetime=catt(put(today(),mmddyyd10.),':',put(time(),time8.));
  want=((input(compress(substr(add_datetime,1,10),'-'),mmddyy8.))*86400) 
  +
  (input(substr(add_datetime,12,8),TIME8.));
run;

Art, CEO, AnalystFinder.com

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 2 replies
  • 668 views
  • 0 likes
  • 3 in conversation