BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
chris2377
Quartz | Level 8

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;

 

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

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.)

View solution in original post

4 REPLIES 4
FreelanceReinh
Jade | Level 19

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.)

chris2377
Quartz | Level 8
Many thanks @FreelanceReinhard

As for the leading tab characters in the data step code - yes, they're there. I use them to indent the code. Is it something wrong? I've never noticed any problems related to this. Should I avoid using tabs?
Tom
Super User Tom
Super User

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.

FreelanceReinh
Jade | Level 19

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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 937 views
  • 3 likes
  • 3 in conversation