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 2025: Call for Content

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!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 5683 views
  • 0 likes
  • 4 in conversation