Using proc mixed to estimate parameters - 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;

Related

Way to change direction of risk difference in proc freq, without changing data in SAS

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)

How do I stack many frequency tables in SAS

I have a dataset of about 800 observations. I want to get the frequency of 14 variables. I want to get the frequency of these variable by shape (an example). There are 3 different shapes.
An example of doing this one time would obviously be:
proc freq; tables color; by shape;run;
However, I do not want 42 frequency tables. I want one frequency table that has the list of 14 variables on the left side. The top heading will have shape1 shape2 shape3 with the frequencies of each variable underneath them.
It would look like I transposed the data sets by percentage and then stacked them on top of each other.
I have several sets of combinations where I need to do this. I have about 5 different groups of variables and I need to make tables using 3 different by groups (necessitating about 15 tables). The first example I discussed is one example of such groups.
Any help would be appreciated!
Using proc means and proc transpose. I give you some example. You can add more categories.
proc means data=sashelp.class nway n;
class sex age;
output out=class(drop=_freq_ _type_) n=freq;
run;
proc transpose data=class out=class(drop=_name_) prefix=AGE;
by sex;
var freq;
id age;
run;
data class_sum;
set class;
array a(*) age:;
age_sum = sum(of age:);
do i = 1 to dim(a);
a(i) = a(i) / age_sum;
end;
drop i;
run;

SAS Proc-Tabulate: Output single percentage column

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;

Linear Regression in SAS besides PROC REG

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

Using Tabulate for 3-way table

I am trying to output a three way frequency table. I am able to do this (roughly) with proc freq, but would like the control for variable to be joined. I thought proc tabulate would be a good way to customize the output. Basically I want to fill in the cells with frequency, and then customize the percents at a later time. So, have count and column percent in each cell. Is that doable with proc tabulate?
Right now I have:
proc freq data=have;
table group*age*level / norow nopercent;
run;
that gives me e.g.:
What I want:
Here is the code I am using:
proc tabulate data=ex1;
class age level group;
var age;
table age='Age Category',
mean=' '*group=''*level=''*F=10./ RTS=13.;
run;
Thanks!
You can certainly get close to that. You can't really get in 'one' cell, it needs to write each thing out to a different cell, but theoretically with some complex formatting (probably using CSS) you could remove the borders.
You can't use VAR and CLASS together, but since you're just doing percents, you don't need to use MEAN - you should just use N and COLPCTN. If you're dealing with already summarized data, you may need to do this differently - if so then post an example of your dataset (but that wouldn't work in PROC FREQ either without a FREQ statement).
data have;
do _t = 1 to 100;
age = ceil(3*rand('Uniform'));
group = floor(2*rand('Uniform'));
level = floor(5*rand('Uniform'));
output;
end;
drop _t;
run;
proc tabulate data=have;
class age level group;
table age='Age Category',
group=''*level=''*(n='n' colpctn='p')*F=10./ RTS=13.;
run;
This puts N and P (n and column %) in separate adjacent cells inside a single level.