DATA Step, Macro, Functions and more

out of range warning and errors

Reply
Regular Contributor
Posts: 160

out of range warning and errors

i am using the below code and get warnings for out of range and error message as below

STUDY_START = datepart(&StudyStart.); *start date and end date is defined in the macro call and it is date9. format
STUDY_END = datepart(&StudyEnd.);

 

if STUDY_START ne . and STUDY_END = . then do;
%let num = %sysfunc(countw(&timeinterval.,¤));
STUDY_END = STUDY_START + %scan(&timeinterval.,&num.,¤);
end;

 

WARNING: Argument 2 to macro function %SCAN is out of range.
NOTE 137-205: Line generated by the invoked macro "AE_INCPREV_TEST".
31 STUDY_END = STUDY_START + %scan(&timeinterval.,&num.,¤); end; if STUDY_START ne
-
22
31 ! . and STUDY_END ne . then TimeStudy = (STUDY_END - STUDY_START) + 1; if TimeStudy ne .
31 ! and &AnlVar. ne ' ' then do; tmp_ASTDT = datepart(ASTDT); tmp_AENDT =
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string,
a numeric constant, a datetime constant, a missing value, INPUT, PUT.

 

I am not able to figure out what the error and warning is it about.

Trusted Advisor
Posts: 1,554

Re: out of range warning and errors

[ Edited ]

You are mixing datastep statements with macro programing statements.

 

Assuming you are using a datastep (in  amacro program) then change your code to:

 

data want;
 set have;
       STUDY_START = datepart(&StudyStart.);
       STUDY_END = datepart(&StudyEnd.);

      if STUDY_START ne . and STUDY_END = . then 
         num = countw("&timeinterval",'¤');
         STUDY_END = STUDY_START + scan("&timeinterval",num,'¤'); /* excess dot after num was removed */
     end;
     .......... etc. ...........
run;
Trusted Advisor
Posts: 1,554

Re: out of range warning and errors

You cannot use %LET as part of IF statement.
Regular Contributor
Posts: 160

Re: out of range warning and errors

Thanks for the solution. Now i get another error asking for

 

SYMBOLGEN: Macro variable TIMEINTERVAL resolves to
ERROR: The name ¤ is not a valid SAS name.
MPRINT(AE_INCPREV_TEST): num = countw(,¤);
ERROR: The name ¤ is not a valid SAS name.
SYMBOLGEN: Macro variable TIMEINTERVAL resolves to
ERROR: The name ¤ is not a valid SAS name.
MPRINT(AE_INCPREV_TEST): STUDY_END = STUDY_START + scan(,num,¤);
ERROR: The name ¤ is not a valid SAS name.

Trusted Advisor
Posts: 1,554

Re: out of range warning and errors

Please post your full code.

It is importnat to know what is the origin of each macro variable (how is it defined) and is it used correctly.

Super User
Posts: 7,766

Re: out of range warning and errors

We need the code&log, the whole code&log, and nothing but the code&log.

Assume you are before one of those beloved American courts in a TV series.

Just replace "truth" with "code and log".

The error messages without the respective code are UTTERLY, TOTALLY useless.

And post the log in a {i} window, so that the horizontal positioning of the messages is preserved.

Help us in helping you.

 

As for macro programming:

- write the Base SAS code so that it works

- replace code that needs to be dynamic with a macro variable, set the macro variable, and make sure that the code runs

- then, and only then, wrap the code into a macro with parameters

- before using macro logic in combination with Base SAS code, make sure through using %put statements that the macro evaluations work as expected; only then make the Base SAS code within the macro active.

 

NEVER write the whole shebang in one sweep, because then you end up where you are now. Clueless.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Ask a Question
Discussion stats
  • 5 replies
  • 179 views
  • 0 likes
  • 3 in conversation