BookmarkSubscribeRSS Feed
vraj1
Quartz | Level 8

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.

5 REPLIES 5
Shmuel
Garnet | Level 18

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;
Shmuel
Garnet | Level 18
You cannot use %LET as part of IF statement.
vraj1
Quartz | Level 8

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.

Shmuel
Garnet | Level 18

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.

Kurt_Bremser
Super User

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.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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
  • 5 replies
  • 5424 views
  • 0 likes
  • 3 in conversation