Suppose I want to model Y on w, z and the interaction of w and z. PROC REG wants me to make a new variable, u=w*z, and then do a regression on w,z, and u
Isn't there some other proc that is less restrictive, where I could just specify w*z as variable to the regression, like I do in R?
Try PROC MODEL from SAS/ETS.
proc model data=foo;
y = int + Bw*w + Bz*z + Bwz*w*z;
fit y;
quit;
Use the | to delimit your variables. You can specify the depth on interaction terms by using #.
This will do all interaction terms, in this case the model would be height+ age + height*age.
proc glm data=sashelp.class;
model weight = height|age;
run;quit;
This will only do first order terms, i.e. no interaction
proc glm data=sashelp.class;
model weight = height|age #1;
run;quit;
proc glm allows for that functionality
Here is some documentation on it: http://support.sas.com/documentation/cdl/en/statug/63033/HTML/default/viewer.htm#glm_toc.htm
Related
Suppose I have a dataset called example with variable x and y, where both are binary {0,1}. I want to find the risk difference stratified by a variable strata.
proc freq data = example;
table strata*x*y / commonriskdiff(CL=NEWCOMBEMR);
run;
However, suppose I want them in different direction, i.e., I want 0.004 (-0.017, 0.028)
I can do
data example2;
set example;
y_2 = 1 - y;
run;
proc freq data = example2;
table strata*x*y_2 / commonriskdiff(CL=NEWCOMBEMR);
run;
but is there a way to do it directly on proc freq, without the extra step of creating example2 dataset?
commonriskdiff(CL=NEWCOMBEMR column = 2)
I'm using SAS Proc GLM to make predictions for a dependent variable with some missing values. Note that all of the predictor variables are fully observed, i.e., the predictors contain no missing values. The standard syntax is:
proc glm data=test;
class a;
model dv=a b c/solution;
output out=testx p=pred;
run;
Since the predictors have no missing values the output data should contain predictions for the missing values wrt the dependent variable.
My output does not contain predictions for the missing values in the dependent variable.
What am I doing wrong?
You will need to show your work. This example contradicts your claim.
data class;
set sashelp.class;
x = ranuni(1);
if x gt .9 then weight=.;
run;
proc print;
run;
proc glm;
class sex;
model weight=sex height age / solution;
output out=testx p=pred r=r;
run;
proc print;
run;
I am trying to create a prediction interval in SAS. My SAS code is
Data M;
input y x;
datalines;
100 20
120 40
125 32
..
;
proc reg;
model y = x / clb clm alpha =0.05;
Output out=want p=Ypredicted;
run;
data want;
set want;
y1= Ypredicted;
proc reg data= want;
model y1 = x / clm cli;
run;
but when I run the code I could find the new Y1 how can I predict the new Y?
What you're trying to do is score your model, which takes the results from the regression and uses them to estimate new values.
The most common way to do this in SAS is simply to use PROC SCORE. This allows you to take the output of PROC REG and apply it to your data.
To use PROC SCORE, you need the OUTEST= option (think 'output estimates') on your PROC REG statement. The dataset that you assign there will be the input to PROC SCORE, along with the new data you want to score.
As Reeza notes in comments, this is covered, along with a bunch of other ways to do this that might work better for you, in Rick Wicklin's blog post, Scoring a regression model in SAS.
I have a mixed model with the following parameters:
A slope and intercept term for group 1
A different slope and intercept term for group 2
A random effect which is indexed by group/subject within group
Is there a way to model this using proc mixed? I can't seem to figure out how to get different slopes/intercepts for the two groups.
This shows a simple model with separate intercept and slope. First BY GROUP then with GROUPS as a factor, and pooled estimate of error. Maybe if you should some example data we can figure the RANDOM part.
data group;
do group=1,2;
do x = 1 to 10;
y = rannor(1);
output;
end;
end;
Run;
ods select SolutionF;
proc mixed;
by group;
model y = x / solution;
run;
ods select SolutionF;
proc mixed;
class group;
model y = group x(group) / noint solution;
run;
I want to use proc tabulate to summarize the percentage of beneficiaries that fall under each of the three categorical variable V1-V3 (this is a person level data-set that we're looking at). I have the following proc step which works fine but produces the perentage as PctN_1110, PctN_1100 etc. But I would like to just get one percentage column (which would be kind of the union of the percentage columns provided). I know I can do this in a data-step after the proc step but I wanted to know if there was a way of achieving this in the proc tabulate step. Thanks!
Proc tabulate date = in_datea
Out = out_data;
Var X1 X2 X3;
Table (V1 all) * (V2 all) * (V3 all), N pctn<V3 all>;
Run;
I'm not sure what you are trying to achieve but the below code is based on my understanding of your question.
proc format ;
picture mypct low-high='000.00,009.00%';
run;
proc tabulate data=in_data out=out_data;
class Var X1 X2 X3;
tables ((V1 )all),(V2(all)),(v3)
(all)*( N reppctN*f=pctfmt7.1)/rts=20 ;
run;