BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi,

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);
run;
1 REPLY 1
Cynthia_sas
SAS Super FREQ
Hi:
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:
http://support.sas.com/forums/thread.jspa?messageID=6392᣸
http://support.sas.com/forums/thread.jspa?messageID=7041ᮁ

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


cynthia

[pre]
*** 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;
%end;
%else %if %upcase(&indata) = SASHELP.SHOES %then %do;
var region product sales;
%end;
run;
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(indata=sashelp.shoes, outht=shoes.html);
%runprt(indata=, outht=default.html);
[/pre]

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 889 views
  • 0 likes
  • 2 in conversation