Hi everyone,
I am very new in SAS.
I am trying to loop a SAS macro.
%let E1 = APPLE;
%let E2 = YAHOO;
%let E3 = SAS;
.....
%MARCO FILTER_NAME(VAR1=. VAR2=);
proc SQL;
...
%MEND FILTER_NAME;
%MACRO LOOP;
%do i=1 %to 3;
%FILTER_NAME(VAR1=filename_&&E&i, VAR2 = output_filename_&&E&i ) /*trying to pass the variable E1 with name Apple inside here*/
%end;
%MEND LOOP;
Something is wrong above. Anybody know how?
If you are just starting to learn SAS then you should first concentrate on learning how to write SAS code. Once you know how to write SAS code you could then begin to learn how to use the SAS macro language to tell SAS how to write the SAS code for you.
That being said your program looks basically ok. There are a couple of typos. But perhaps the main missing thing is that there you never call the macro that you defined.
%let E1 = APPLE;
%let E2 = YAHOO;
%let E3 = SAS;
%MACRO FILTER_NAME(VAR1,VAR2);
%put VAR1=&var1;
%put VAR2=&var2;
%MEND FILTER_NAME;
%MACRO LOOP;
%do i=1 %to 3;
%FILTER_NAME(VAR1=filename_&&E&i, VAR2 = output_filename_&&E&i )
%end;
%MEND LOOP;
%loop;
While Tom is 100% correct about learning SAS language before learning macro language, here are some secondary considerations.
The problem may lie inside the definition of %FILTER_NAME. Some possibilities:
If you were to post more of what is inside your macro, you may find you receive more than debugging help ... how to achieve the same result in a cleaner, more efficient way.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.