I don't know if it is the right place to post this, but it seemed to me I would be more likely to get an answer there.
Currrently working on SAS for an internship, I am trying to write a macro in order to automate the process of finding a fitting ARIMA
model for my data sets. I am very new to this software, and quite not a specialist in the field of statistics.
However, while I seemingly understood how to import my files and launch the proc arima
, I am stuck on a little problem. A part of my code, which is working fine if I write it outside of the macro (I guess it's called open code
?) like this :
data _null_;
set Lib.out; /* Lib.out contains the data of the OUTSTAT statement of the PROC ARIMA */
x = 1000000;
put _STAT_; /* Prints correctly the names of the different lines in the log */
if _STAT_='AIC' then do; /* _STAT_ is a column and AIC the name of a line AFAIK */
if _VALUE_ < x then
x = _VALUE_;
put x;
put _STAT_; /* Here only prints AIC, which I guess is correct inside of the IF loop */
end;
run;
But when running it inside a macro such as :
%macro recherche(poste=, mto=);
--- code ---
data _null_;
set Lib.out; /* Lib.out contains the data of the OUTSTAT statement of the PROC ARIMA */
%let aic0 = 1000000;
%put _STAT_; /* Doesn't recognize the _STAT_ statement and stops */
%if _STAT_='AIC' %then %do;
%if _VALUE_ < &aic0 %then %do;
&aic0 = _VALUE_;
data Lib.chosen;
set Lib.model; /* Contains the OUTMODEL statement of PROC ARIMA */
run;
%end;
end;
run;
--- code ---
I tried to search for similar cases on the internet but couldn't find an explanation for what I am looking for. Plus, being new to SAS, the official documentation is still hard to understand. Thanks in advance.
Most of what you're doing there doesn't need the %
. You just need that if it's a statement controlling which lines of code are even sent to the compiler.
%macro recherche(mto=);
data _null_;
set Lib.out; /* Lib.out contains the data of the OUTSTAT statement of the PROC ARIMA */
x = &mto.;
put _STAT_; /* Prints correctly the names of the different lines in the log */
if _STAT_='AIC' then do; /* _STAT_ is a column and AIC the name of a line AFAIK */
if _VALUE_ < x then
x = _VALUE_;
put x;
put _STAT_; /* Here only prints AIC, which I guess is correct inside of the IF loop */
end;
run;
%mend recherche;
That's assuming the MTO parameter is intended to hold the value assigned to x. The only time you would use %IF is if you did something like
%macro recherche(mto=,stat=);
data _null_;
set Lib.out; /* Lib.out contains the data of the OUTSTAT statement of the PROC ARIMA */
x = &mto.;
put _STAT_; /* Prints correctly the names of the different lines in the log */
%if &stat=AIC %then %do;
if _STAT_='AIC' then do; /* _STAT_ is a column and AIC the name of a line AFAIK */
if _VALUE_ < x then
x = _VALUE_;
put x;
put _STAT_; /* Here only prints AIC, which I guess is correct inside of the IF loop */
end;
%end;
%else %if &stat=XYZ %then %do;
*more code ...;
%end;
run;
%mend recherche;
That would only do one or the other of those sections of code. Macro statements don't have access to the data in the proc or data step, and they don't use quotes (unless the quote is an actual important part of the code).