Categorical Data Analysis With SAS

/* SALES – Categorical Data Analysis */
proc format ;
value purfmt 1 = “100$ +”
0 = “<100$”;
value incfmt 1 = “Low Earners”
2 = “Medium Earners”
3 = “High Earners”;
run;

* Check frequency distribution of categorical/ordered variables;
ods graphics / width= 500;

title ‘Frequency Tables for Data – Sales’;
proc freq data = sales;
tables Purchase Gender Income
Gender*Purchase
Income*Purchase
/ plots = freqplot;

format Purchase purfmt.;
run;
title;

* check distribution of continuous variable;

ods select histogram probplot;

proc univariate data = Sales;
var Age;
Histogram Age / normal (mu = est sigma = est);
probplot Age / normal (mu = est sigma = est) ;
run;

* No obvious outliers so move on. Distribution in general does not matter

* Create new data set for ordinal values rearrangement;

data newsales;
set sales;
if Income = “Low” Then IncLevel = 1;
else if Income = “Medium” Then IncLevel = 2;
else if Income = “High” Then IncLevel = 3;
run;
ods graphics / width = 1000;
title “Frequency dist. with correct Inclevel”;
proc freq data = newsales;
tables Inclevel*Purchase / plots = freqplot;
format Purchase purfmt. Inclevel Incfmt.;
run;
title;

* Performing Pearson Chi Square Test of Association;
ODS graphics / width=500;
title1 “Ass. Between Gender and Purchase”;
proc freq data = newsales;
tables Gender*Purchase /
Chisq expected cellchi2 nocol relrisk con plots=all;
format Purchase purfmt.;
run;

ODS graphics / width=500;
title1 “Ordinal Test Example”;
proc freq data = newsales;
tables Gender*Purchase /
cmh relrisk ;
format Purchase purfmt.;
run;
* Runnning for Ordinal ass between IncLevel & Purchase;
proc freq data = newsales;
tables IncLevel*Purchase /
Chisq measures cl plots=all;
format Purchase purfmt. Inclevel incfmt.;
run;

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s