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.
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;
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.
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.
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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.