Hi,
I'm trying to calculate time interval between two days stroed as macro variables like this:
%let start_date = %sysfunc(mdy(12,31,2018));
%let end_date = %sysfunc(mdy(12,31,2019));
%let dif = %sysfunc(intck('qtr', &start_date, &end_date));
But I get an error saying:
WARNING: An argument to the function INTCK referenced by the %SYSFUNC or %QSYSFUNC macro
function is out of range.
NOTE: Mathematical operations could not be performed during %SYSFUNC function execution. The
result of the operations have been set to a missing value.
IF I do it in a data step, it works, so I guess there is some issue with the macro variable assignment?
data test;
input start_date :date. end_date :date.;
datalines;
"31dec2018"d "31dec2019"d
;
run;
data test;
set test;
dif = intck('qtr', start_date, end_date);
run;
Hi @chris2377,
In the DATA step the single quotes around the first argument of the INTCK function indicate correctly that the three letters qtr are a character argument, i.e., text (and not a variable name). For the macro processor, however, basically everything is text -- including those single quotes, which are therefore misinterpreted as part of the INTCK function argument. Just remove the quotes:
%let dif = %sysfunc(intck(qtr, &start_date, &end_date));
(BTW, you don't need the quotes and the trailing "d" when reading date values with the DATE. informat. Also, there are leading tab characters in your DATA step code.)
Hi @chris2377,
In the DATA step the single quotes around the first argument of the INTCK function indicate correctly that the three letters qtr are a character argument, i.e., text (and not a variable name). For the macro processor, however, basically everything is text -- including those single quotes, which are therefore misinterpreted as part of the INTCK function argument. Just remove the quotes:
%let dif = %sysfunc(intck(qtr, &start_date, &end_date));
(BTW, you don't need the quotes and the trailing "d" when reading date values with the DATE. informat. Also, there are leading tab characters in your DATA step code.)
TABS in code is a heated debate, but TABS in data is serious mistake.
Do not indent the lines of data. How will know where column 3 is?
To make it easier to remember also do not indent the DATALINES (aka CARDS) statement. Then it will be easier to remember not to indent the lines of data.
You're welcome.
It depends on the user interface and its settings how tab characters in code or datalines are handled. So it can happen that code reading datalines including tabs works without problems with one user interface, but causes problems with a different user interface. Last week this issue occurred in another thread. Using spaces instead ensures that SAS code and datalines are handled consistently in SAS Studio, the traditional Display Manager interface, SAS Enterprise Guide or whatever interface people are using.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.