BookmarkSubscribeRSS Feed
Moh
Obsidian | Level 7 Moh
Obsidian | Level 7

Hi, folks - 

I want to develop some statistical models using different training samples and then test their forecasting power on different holdout sample. For this purpose, I used window rolling approach in where both training and holdout sample move ahead untile specific year.

%let LT=2000;

%let UT=2005;

%let LH=2006;

%let UH=2008;

%macro_static_models(LT=&LT, UT=&UT, LH=&LH, UH=&UH);

so in the next round, I want to move one year ahead and have;

%let LT=2001;

%let UT=2006;

%let LH=2007;

%let UH=2009;

% macro_static_models (LT=&LT, UT=&UT, LH=&LH, UH=&UH) ;

 

the LT will stop at 2009. Do you have any suggestion how can I incorporate Do loop?

Thanks

4 REPLIES 4
Reeza
Super User

Use call execute.

 

data want;

lt=1999; ut=2004;

do i=1 to 10;
   lt=lt+1;
   ut=ut+1;

    str=cats('%macro_static_models(LT=', lt, ',UT=', UT, ');');

    call execute(str);

end;
run;



PGStats
Opal | Level 21

Using call execute to call a macro is safer if you prevent macro expansion at the call time with %nrstr

 


data _null_;
length line $200;
do lt = 2000 to 2009;
    line = cats('%nrstr(%macro_static_models(LT=', lt, ',UT=', lt+5, ',LH=', lt+6, ',UH=', lt+8, '));');
    call execute(line);
    end;
run;
PG
Moh
Obsidian | Level 7 Moh
Obsidian | Level 7

many thanks for your reply. Actually, I forgot to add something else. I need to define new libraries for each round of tests. 

I use the last two digits of each year as a proxy for lib names, e.g. S&LTS&UHS&Y.C.

 

%let LT=2000;

%let UT=2005;

%let LH=2006;

%let UH=2008;

%let LTS=00;

%let UTS=05;

%let LHS=06;

%let UHS=08;

 

%macro_static_models(LT=&LT, UT=&UT, LH=&LH, UH=&UH);

 

Would you please kindly help me ? thanks

Reeza
Super User

I'm not sure how that changes anything. You can use the libname function inside a data null step to create the library based on the LT/UT variables.

 


Why are you creating macro variables outside your process, its better to keep it internal to your process.

 

data _null_;

lts=substr("&lt", 3, 2);
uts=substr("&ut", 3, 2);

rc=libname(cats(dir, lts, uts));

run;

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!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 1475 views
  • 0 likes
  • 3 in conversation