BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
rimob
Fluorite | Level 6

Hello,

 

 

i want to run a macro with 2 variables, first one with period from 201801 to 201901 and the second with a table name:

 

 

%macro do_list;
%do I=201801 %to 201812;
%do j in ("Mag1","Mag2","Mag2");
%import(luna=&I.,vendor=&J.);
%put &I. &J.;
%end;
%end;
%import(luna=201901,Vendor=Mag1);
%import(luna=201901,Vendor=Mag2);
%import(luna=201901,Vendor=Mag3);
%mend;
%do_list;

 

 

i'm trying this but i have the following error : 

 

 

ERROR: An unexpected semicolon occurred in the %DO statement. A dummy macro will be compiled.

ERROR 180-322: Statement is not valid or it is used out of proper order.

 

 

 

could you help with a solution ? 

 

 

thank you for your help!

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
%do j in ("Mag1","Mag2","Mag2");

is not valid syntax and will not work.

 

A simplified version of the j-loop portion code that does work (note that we don't normally use quotes around the values assigned to macro variables):

 

%macro oink;
    %let stuff=Mag1 Mag2 Mag3;
    %do j = 1 %to 3;
		%let thisname=%scan(&stuff,&j,%str( ));
		%put &=j &=thisname;
    %end;
%mend;

%oink

Also hint hint hint, when you have error messages from a SAS macro, use this command at the start of the program to try to debug

 

options mprint symbolgen mlogic; 

 

--
Paige Miller

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26
%do j in ("Mag1","Mag2","Mag2");

is not valid syntax and will not work.

 

A simplified version of the j-loop portion code that does work (note that we don't normally use quotes around the values assigned to macro variables):

 

%macro oink;
    %let stuff=Mag1 Mag2 Mag3;
    %do j = 1 %to 3;
		%let thisname=%scan(&stuff,&j,%str( ));
		%put &=j &=thisname;
    %end;
%mend;

%oink

Also hint hint hint, when you have error messages from a SAS macro, use this command at the start of the program to try to debug

 

options mprint symbolgen mlogic; 

 

--
Paige Miller
RW9
Diamond | Level 26 RW9
Diamond | Level 26

You can simplify things by using Base SAS (as always):

data _null_;
  do i=201801 to 201812;
    do j="Mag1","Mag2","Mag3";
      call execute(cats('%import(luna=',put(i,best.),',vendor=',j,');'));
    end;
  end;
run;
rimob
Fluorite | Level 6

Thank you for your help, both solutions from RW9 and PaigeMiller working.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 658 views
  • 0 likes
  • 3 in conversation