turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- General Programming
- /
- calculate a time interval using macro variables

Topic Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

05-01-2014 07:29 PM

I'm stuck trying to calculate the time interval between &systime and the current time, in minutes. I've looked for examples in books and online, but they all seem to focus on using &sysdate or &systime in a title or footnote. I'm new to macros, and I'm running version 6.1 of SAS on Demand for Professionals on a Lenovo PC with Windows 8.1.

Accepted Solutions

Solution

05-01-2014
07:41 PM

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to janetts

05-01-2014 07:41 PM

&SYSTIME is time part of when the SAS session started. &SYSDATE (or &SYSDATE9) is the datepart.

DATETIME() function can be used to find the current time.

So to find the number of seconds just take the difference of the two.

%let seconds = %sysevalf(%sysfunc(datetime())-"&sysdate9:&systime"dt) ;

Just divide by 60 to get the number of minutes.

All Replies

Solution

05-01-2014
07:41 PM

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to janetts

05-01-2014 07:41 PM

&SYSTIME is time part of when the SAS session started. &SYSDATE (or &SYSDATE9) is the datepart.

DATETIME() function can be used to find the current time.

So to find the number of seconds just take the difference of the two.

%let seconds = %sysevalf(%sysfunc(datetime())-"&sysdate9:&systime"dt) ;

Just divide by 60 to get the number of minutes.

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

05-01-2014 07:57 PM

I tried it and it worked. Thanks!

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to janetts

05-01-2014 07:44 PM

Is there any chance that this program will ever be run with a session that starts before midnight and runs after midnight? You'll need to incorporate the date parts to get proper results.

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to janetts

05-01-2014 07:49 PM

Time in sas is in seconds, so 60 is 60 seconds and 180 is 3 minutes.

You can do straight additions/subtraction with the time variables and then divide by 60 to get the number of minutes.

For evaluating functions in macro language you'll need to use %eval to resolve the subtraction.