Help using Base SAS procedures

Repeating a Proc statement

Posts: 0

Repeating a Proc statement


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?

Code used:
Proc Autoreg data=work;
Model Var1=/garch=(p=1,q=1);
Posts: 8,743

Re: Repeating a Proc statement

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.

The way to write a macro program is to start with a working SAS program. Do you need to generate code to analyze all 33 variables?? No -- but you should at least have a sense for the kind of code you need to analyze 2 or 3 of the 33 variables so you can begin to identify patterns in the code and places where macro variable substitution can take place. Here are some forum postings about macro processing that may be helpful:᣸ᮁ

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, 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 listing;
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;
%mend runprt;

** now run the macro program;
%runprt(indata=sashelp.class, outht=class.html);
%runprt(indata=sashelp.prdsale, outht=prd.html);
%runprt(, outht=shoes.html);
%runprt(indata=, outht=default.html);
Ask a Question
Discussion stats
  • 1 reply
  • 2 in conversation