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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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