I made macro %dataload
and want to load data once by using loop.. not that listing
%dataload(year=16,month=09);
%dataload(year=16,month=10);
%dataload(year=16,month=11);
%dataload(year=17,month=12);
%dataload(year=17,month=01);
%dataload(year=17,month=02);
%dataload(year=17,month=03);
%dataload(year=17,month=04);
%dataload(year=17,month=05);
%dataload(year=17,month=06);
%dataload(year=17,month=07);
%dataload(year=17,month=08);
%dataload(year=17,month=09);
%dataload(year=17,month=10);
%dataload(year=17,month=11);
can I use do loop?
for example
%let start_year=16
%let end_year=18
do i = start_year to end_year;
do j= 1 to 12;
%dataload(year=i,month=j)
end;
end;
You can.
Is something not working for you?
CALL EXECUTE is usually simpler however.
@asdfsa wrote:
I made macro %dataload
and want to load data once by using loop.. not that listing
%dataload(year=16,month=09);
%dataload(year=16,month=10);
%dataload(year=16,month=11);
%dataload(year=17,month=12);
%dataload(year=17,month=01);
%dataload(year=17,month=02);
%dataload(year=17,month=03);
%dataload(year=17,month=04);
%dataload(year=17,month=05);
%dataload(year=17,month=06);
%dataload(year=17,month=07);
%dataload(year=17,month=08);
%dataload(year=17,month=09);
%dataload(year=17,month=10);
%dataload(year=17,month=11);
can I use do loop?
for example
%let start_year=16
%let end_year=18
do i = start_year to end_year;
do j= 1 to 12;
%dataload(year=i,month=j)
end;
end;
The macro PREprocessor does its work (generating code!) before any Base SAS code starts to run. Since your macro will leave Base SAS code in its place, that will destroy any data step logic.
To call a macro from a data step (using values created in the data step), use call execute().
Hello,
You have to use macro loops (and use & to resolve macrovariables values) :
%let start_year=16
%let end_year=18
%do i = &start_year. %to &end_year.;
%do j= 1 to 12;
%dataload(year=&i.,month=&j.)
%end;
%end;
Edit : Note that a macro loop can only be used inside a macro :
%macro mymacro;
/* macro code */
...
%mend;
%mymacro;
You can.
Is something not working for you?
CALL EXECUTE is usually simpler however.
@asdfsa wrote:
I made macro %dataload
and want to load data once by using loop.. not that listing
%dataload(year=16,month=09);
%dataload(year=16,month=10);
%dataload(year=16,month=11);
%dataload(year=17,month=12);
%dataload(year=17,month=01);
%dataload(year=17,month=02);
%dataload(year=17,month=03);
%dataload(year=17,month=04);
%dataload(year=17,month=05);
%dataload(year=17,month=06);
%dataload(year=17,month=07);
%dataload(year=17,month=08);
%dataload(year=17,month=09);
%dataload(year=17,month=10);
%dataload(year=17,month=11);
can I use do loop?
for example
%let start_year=16
%let end_year=18
do i = start_year to end_year;
do j= 1 to 12;
%dataload(year=i,month=j)
end;
end;
As @gamotte already implied, you would have to use a macro loop. One possibility is to rewrite your %dataload macro to a recursive version:
%macro dataload(year=,month=,from=,to=);
%if %length(&from) and %length(&to) %then %do;
%do from=&from %to &to;
%if %substr(&from,3)=13 %then /* new year */
%let from=%eval(&from+88);
%dataload(year=%substr(&from,1,2),month=%substr(&from,3));
%end;
%return;
%end;
/* here goes the contents of the original macro */
%mend;
You could then call the macro as
%dataload(from=1609,to=1711);
Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.
Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.
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.