VARMAX modelling in SAS - sas

I want to know what the difference is when inserting variables in proc reg and then forecast the residuals with VARMAX
and
inserting the significant variables from proc reg to the VARMAX modelling.
In code:
Proc reg data=x printall;
dependent_variable=exogenous_variable1 exogenous_variable2 ... exogenous_variablep
white vif tol dw dwprob selection=b slentry=0.05;
output out=xforecast Rstudent=Rstudent student=student covratio=covratio h=h predicted=pred residual=residual;
Proc varmax data=xforecast
model residual/
p=7 q=2
method=ls dftest minic=(type=aic) print=(roots);
nloptions;
garch p=1 q=1 form=ccc;
output out=forecast1 lead=21;
run;
Or with only VARMAX:
proc varmax data=xforecast printall;
dependent_variable=exogenous_variable1 exogenous_variable2 ... exogenous_variablep/
p=7 q=2 method=ls dftest minic=(type=aic) print=(roots);
nloptions;
garch p=1 q=1 form=ccc;
output out=forecast1 lead=21;
With only running VARMAX it is also not possible to generate a forecast which i don't understand. The error code:
WARNING: The value of LEAD=21 in OUTPUT statement. There are only 0 future independent observations. The value of LEAD will take
the minimum of two values.

Related

Using SAS macro

Here is code:
%macro do_regression(dep);
proc glimmix data=xxx;
class group id intv month1;
model &dep = group month1 group*month1/d=normal link=identity;
random intv(id);
lsmeans group*month1/ilink diff cl ;
lsmestimate group*month1 'bsl-3 ' 1 -1 0 0 -1 1 0 0/cl ;
lsmestimate group*month1 'bsl-6' 1 0 -1 0 -1 0 1 0/cl;
ods output LSMEstimates
run; quit;
%mend;
%do_regression(original total domain1)
Here is example of data structure:
Question: I am new to SAS macros and am working with a SAS macro code to run the following regression model for three outcome variables (original total domain1). I output the results using: ods output LSMEstimates which created three datasets named data1—data3 with the estimates. However, I cannot figure out how to attach the outcome variable names of these datasets. Eventually, I would only want the following to be stored in one final dataset that can “set” data1—data3: effect label estimate lower upper. [I only want to store estimates from the two lsmestimate statements shown that I am outputting using: ods output LSMEstimates]
To aggregate the datasets you can use PROC APPEND.
ods output LSMEstimates=lsm;
run;quit;
proc append data=lsm base=lsm_aggregate force;
run;
If the value/variable &DEP is not already in the dataset generated by the ODS OUTPUT statement then add a step to add it.
data lsm_dep ;
length dep $32 ;
dep = "&dep";
set lsm;
run;
proc append data=lsm_dep base=lsm_aggregate force;
run;
Make sure to remove the LSM_AGGREGATE dataset before running a new batch of models.
proc delete data=lsm_aggregate; run;
%do_regression(original )
%do_regression(total )
%do_regression(domain1)

Missing values in VARMAX

I have a dataset with visitors and weather variables. I'm trying to forecast visitors based on the weather variables. Since the dataset only consists of visitors in season there is missing values and gaps for every year. When running proc reg in sas it's all okay but the issue comes when i'm using proc VARMAX. I cannot run the regression due to missing values. How can i tackle this?
proc varmax data=tivoli4 printall plots=forecast(all);
id obs interval=day;
model lvisitors = rain sunshine averagetemp
dfebruary dmarch dmay djune djuly daugust doctober dnovember ddecember
dwednesday dthursday dfriday dsaturday dsunday
d_24Dec2016 d_05Dec2013 d_24Dec2017 d_24Dec2014 d_24Dec2015 d_24Dec2019
d_24Dec2018 d_24Sep2012 d_06Jul2015
d_08feb2019 d_16oct2014 d_15oct2019 d_20oct2016 d_15oct2015 d_22sep2017 d_08jul2015
d_20Sep2019 d_08jul2016 d_16oct2013 d_01aug2012 d_18oct2012 d_23dec2012 d_30nov2013 d_20sep2014 d_17oct2012 d_17jun2014
dFrock2012 dFrock2013 dFrock2014 dFrock2015 dFrock2016 dFrock2017 dFrock2018 dFrock2019
dYear2015 dYear2016 dYear2017
/p=7 q=2 Method=ml dftest;
garch p=1 q=1 form=ccc OUTHT=CONDITIONAL;
restrict
ar(3,1,1)=0, ar(4,1,1)=0, ar(5,1,1)=0,
XL(0,1,13)=0, XL(0,1,14)=0, XL(0,1,13)=0, XL(0,1,27)=0, XL(0,1,38)=0, XL(0,1,42)=0;
output lead=10 out=forecast;
run;
As with any forecast, you will first need to prepare your time-series. You should first run through your data through PROC TIMESERIES to fill-in or impute missing values. The impute choice that is most appropriate is dependent on your variables. The below code will:
Sum lvisitors by day and set missing values to 0
Set missing values of averagetemp to average
Set missing values of rain, sunshine, and your variables starting with d to 0 (assuming these are indicators)
Code:
proc timeseries data=have out=want;
id obs interval = day
setmissing = 0
notsorted
;
var lvisitors / accumulate=total;
crossvar averagetemp / accumulate=none setmissing=average;
crossvar rain sunshine d: / accumulate=none;
run;
Important Time Interval Consideration
Depending on your data, this could bias your error rate and estimates since you always know no one will be around in the off-season. If you have many missing values for off-season data, you will want to remove those rows.
Since PROC VARMAX does not support custom time intervals, you can instead create a simple time identifier. You can alternatively turn this into a format for proc format and converttime_id at the end.
data want;
set have;
time_id+1;
run;
proc varmax data=want;
id time_id interval=day;
...
output lead=10 out=myforecast;
run;
data myforecast;
merge myforecast
want(keep=time_id date)
;
by time_id;
run;
Or, if you made a format:
data myforecast;
set myforecast;
date = put(time_id, timeid.);
drop time_id;
run;

Output the dropped/excluded observation in Proc GLIMMIX - SAS

When I run a proc glimmix in SAS, sometimes it drops observations.
How do I get the set of dropped/excluded observations or maybe the set of included observations so that I can identify the dropped set?
My current Proc GLIMMX code is as follows-
%LET EST=inputf.aarefestimates;
%LET MODEL_VAR3 = age Male Yearc2010 HOSPST
Hx_CTSURG Cardiogenic_Shock COPD MCANCER DIABETES;
data work.refmodel;
set inputf.readmref;
Yearc2010 = YEAR - 2010;
run;
PROC GLIMMIX DATA = work.refmodel NOCLPRINT MAXLMMUPDATE=100;
CLASS hospid HOSPST(ref="xx");
ODS OUTPUT PARAMETERESTIMATES = &est (KEEP=EFFECT ESTIMATE STDERR);
MODEL RADM30 = &MODEL_VAR3 /Dist=b LINK=LOGIT SOLUTION;
XBETA=_XBETA_;
LINP=_LINP_;
RANDOM INTERCEPT/SUBJECT= hospid SOLUTION;
OUTPUT OUT = inputf.aar
PRED(BLUP ILINK)=PREDPROB PRED(NOBLUP ILINK)=EXPPROB;
ID XBETA LINP hospst hospid Visitlink Key RADM30;
NLOPTIONS TECH=NRRIDG;
run;
Thank you in advance!
It drops records with missing values in any variable you're using in the model, in a CLASS, BY, MODEL, RANDOM statement. So you can check for missing among those variables to see what you get. Usually the output data set will also indicate this by not having predictions for the records that are not used.
You can run the code below.
*create fake data;
data heart;set sashelp.heart; ;run;
*Logistic Regression model, ageCHDdiag is missing ;
proc logistic data=heart;
class sex / param=ref;
model status(event='Dead') = ageCHDdiag height weight diastolic;
*generate output data;
output out=want p=pred;
run;
*explicitly flag records as included;
data included;
set want;
if missing(pred) then include='N'; else include='Y';
run;
*check that Y equals total obs included above;
proc freq data=included;
table include;
run;
The output will show:
The LOGISTIC Procedure
Model Information
Data Set WORK.HEART
Response Variable Status
Number of Response Levels 2
Model binary logit
Optimization Technique Fisher's scoring
Number of Observations Read 5209
Number of Observations Used 1446
And then the PROC FREQ will show:
The FREQ Procedure
Cumulative Cumulative
include Frequency Percent Frequency Percent
ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ
N 3763 72.24 3763 72.24
Y 1446 27.76 5209 100.00
And 1,446 records are included in both of the data sets.
I think I answered my question.
The code line -
OUTPUT OUT = inputf.aar
gives the output of the model. This table includes all the observations used in the proc statement. So I can match the data in this table to my input table and find the observations that get dropped.
#REEZA - I already looked for missing values for all the columns in the data. Was not able to identify the records there are getting dropped by only identifying the no. of records with missing values. Thanks for the suggestion though.

sas, how can i retrieve a value from regression result and assign to a variable

how i can do if I want to assign i to intercept to make i = 906.73916.thanks
Parameter Estimates
Parameter Standard
Variable Label DF Estimate Error t Value Pr > |t|
Intercept Intercept 1 906.73916 28.26505 32.08 <.0001
acs_k3 avg class size k-3 1 -2.68151 1.39399 -1.92 0.0553
meals pct free meals 1 -3.70242 0.15403 -24.04 <.0001
full pct full credential 1 0.10861 0.09072 1.20 0.2321
ODS is very helpful for this. The names of different output components differ for different procs. Example for PROC REG below, should be about the same for most regression PROCS:
ods output ParameterEstimates=MyIntercept(where=(Variable="Intercept"));
proc reg data=sashelp.class;
model weight=age;
run;
quit;
ods output close;
proc print data=MyIntercept;
run;

SAS PROC CORR output

In SAS proc corr, I want the output to show only Pearson Correlation Coefficient.
By default, the output also shows the following :- Prob > |r| under H0: Rho=0 and Number of observations. How do I do this? Thanks for your help.
I would output a dataset and then proc print or report or whatnot that dataset.
proc corr data=sashelp.class out=corrcoeff(where=(_type_='CORR');
var age height weight;
run;