DATA Step, Macro, Functions and more

%DO statement is not valid in open code

Reply
Contributor
Posts: 31

%DO statement is not valid in open code

Good morning,

Here is the macro variables I created but I got error message and I am not sure why? Could you please help? Thank you! Y

ERROR: The %DO statement is not valid in open code.

[/prep]
%let org_date = "16Dec2009"d;
%let calendar_mn = 3;

%macro get_all;
%do increm=1 %to &calendar_mn %do;
data cal_date;
decrem=&increm-1;

if decrem=0 then beg_date = &org_date;
else beg_date = intnx('month', &org_date, decrem );
end_date = intnx('month', &org_date, &increm );

call symput("beg_date", compress(put(beg_date, 11.)));
call symput("end_date", compress(put(end_date, 11.)));
run;

%end;
%mend get_all;

%get_all

[/prep]
PROC Star
Posts: 7,474

Re: %DO statement is not valid in open code

Ying,

Not sure why you would get that particular error message, but you have an extra %do.

That is, you have:

%do increm=1 %to &calendar_mn %do;

but should only have had:

%do increm=1 %to &calendar_mn;

HTH,
Art
Super Contributor
Super Contributor
Posts: 3,174

Re: %DO statement is not valid in open code

Suggest pasting your SAS-generated log as you see it into a post-repy here, rather than just your SAS code.

Scott Barry
SBBWorks, Inc.
Contributor
Posts: 31

Re: %DO statement is not valid in open code

Thank you so much, art297! The ERROR's gone!
Valued Guide
Posts: 634

Re: %DO statement is not valid in open code

Not that it particularly matters, but....

[pre]%do increm=1 %to &calendar_mn %do;[/pre]

I suspect that the second, extra, %DO is masked during macro compilation by the first %DO statement, and then exposed during macro execution - thus the 'in open code error'. Although I am surprised that there was not an error during the macro compilation of the iterative %DO statement.
Ask a Question
Discussion stats
  • 4 replies
  • 2990 views
  • 0 likes
  • 4 in conversation