The script begins by displaying the first 24 observations of the `Sashelp.Margarin` dataset using `PROC PRINT`, sorted by `HouseID` and `Set`. Then, it executes `PROC BCHOICE` to fit a Bayesian choice model. The model includes classification variables (`Brand`, `HouseID`, `Set`), a main model term (`Choice` as a function of the choice set `HouseID` and `Set`), and random effects for `Brand` and `LogPrice` at the subject level `HouseID`, with re-centering on `LogInc` and `FamSize`.
Data Analysis
Type : SASHELP
The script exclusively uses the `Sashelp.Margarin` dataset, an example dataset built into SAS.
1 Code Block
PROC PRINT
Explanation : This block uses `PROC PRINT` to display the first 24 rows of the `Sashelp.Margarin` dataset. Observations are grouped and identified by the `HouseID` and `Set` variables. It provides an initial overview of the data before analysis.
Copied!
proc print data=Sashelp.Margarin (obs=24);
by HouseID Set;
id HouseID Set;
run;
1
PROC PRINTDATA=Sashelp.Margarin (obs=24);
2
BY HouseID SET;
3
id HouseID SET;
4
RUN;
2 Code Block
PROC BCHOICE
Explanation : This block executes `PROC BCHOICE` to perform a Bayesian discrete choice analysis. The `Sashelp.Margarin` dataset is used. The `seed`, `nmc`, `thin`, `nthreads` options control the Markov Chain Monte Carlo (MCMC) simulation. Variables `Brand`, `HouseID`, `Set` are declared as classification variables. The model specifies that `Choice` depends on the choice set defined by `HouseID` and `Set`. Random effects are defined for `Brand` and `LogPrice` at the subject level `HouseID`, with covariates (`LogInc`, `FamSize`) for re-centering of random effects.
Copied!
proc bchoice data=Sashelp.Margarin seed=123 nmc=40000 thin=2
nthreads=4 plots=none;
class Brand(ref='PPk') HouseID Set;
model Choice = / choiceset=(HouseID Set);
random Brand LogPrice / subject=HouseID remean=(LogInc FamSize)
type=un monitor=(1);
run;
random Brand LogPrice / subject=HouseID remean=(LogInc FamSize)
6
type=un monitor=(1);
7
RUN;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.