I have a dataset of 33 variables and I would like to run Proc Autoreg function on each of these variables. Is there any loop function available in SAS which will allow me to run the regression automatically for each of the 32 other variables?
Proc Autoreg data=work;
There is a way to generate SAS code using the SAS Macro facility. However, in order to generate a SAS macro program to do what you want, you need to know how PROC AUTOREG works...can you have 33 model statements? Do you need to have 33 calls to PROC AUTOREG?? What is the correct syntax to generate the results you want.
There's a simple macro program below that runs multiple proc prints. Before you try to write a macro program for you AUTOREG, I suggest the following plan:
1) Have a working SAS program that produces the output you want. For example, the macro program below, has at the heart, the fact that I want a "generic" proc print macro program so I can print files to ODS HTML and specify just the input data set name and the output HTML file name
2) Figure out where you can use macro variables in the code and begin to modify the code to use macro variable references and set the variable values with %LET
3) Then design your macro program (defined with %MACRO/%MEND) and create keyword parameters that will take the place of your %LET statements. Add any macro conditional logic that will help you generate the output you need.
4) Test the macro program.
The macro facility documentation is excellent and contains many examples of writing macro programs. For help with PROC AUTOREG and/or with macro programs, Tech Support is a valuable resource.
The program below serves the following purpose within these constraints:
--a: just print 15 obs from any data set
--b: if the input data is sashelp.class, use a var statement for name, age and height
--c: if the input data is sashelp.shoes, use a var statement for region, product, sales
--d: if the input data is anything else, don't use a var statement (which will give all vars in the data set)
--e: if the input data set is NOT specified, then use SASHELP.CLASS as the data set name
--f: use a macro variable INDATA for the name of the input data set
--g: use a macro variable OUTHT for the name of an ODS HTML output file
*** a simple example;
*** define the macro program;
%macro runprt(indata=, outht=);
%if &indata= %then %let indata=sashelp.class;
ods html file="&outht" style=sasweb;
proc print data=&indata (obs=15);
title "The file is: &indata";
%if %upcase(&indata) = SASHELP.CLASS %then %do;
var name age height;
%else %if %upcase(&indata) = SASHELP.SHOES %then %do;
var region product sales;
ods html close;
** now run the macro program;