BookmarkSubscribeRSS Feed
Ying
Fluorite | Level 6
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]
4 REPLIES 4
art297
Opal | Level 21
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
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.
Ying
Fluorite | Level 6
Thank you so much, art297! The ERROR's gone!
ArtC
Rhodochrosite | Level 12
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.

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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
  • 4 replies
  • 6447 views
  • 0 likes
  • 4 in conversation