- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I am trying to write code in SAS University edition to do a 3-way cross tabulation. For example, if I have 3 categorical variables and I want to look at presisting condition status(preex_status) and insurance coverage(coverage_status) by year whether before or after the policy went into effect (year_class). Each variable has two categories the year_Class has 'pre' and 'post' and the other two have 0 and 1 for yes or no response. I wrote following code:
proc freq data = mydata;
tables preex_status*coverage_status*year_Class / chisq;
run;
However it gives a 2*2 table controlling for preex_status. I cannot use the 'By' statement gives me an error saying "data is not sorted in ascending sequence. I was expecting a table as below:
Pre | Post | |||
Coverage status | Pre-existing condition | No | Pre-existing condition | No |
Yes | ||||
No |
Is this possible or am I using the wrong statistical test? Can someone help me solve it? Thank yo
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thanks but that won't work. But i think i might have solved it. I just created a new variable using condition statement and created four categories for the new variable where 1. a person has condition and insurance. 2. Has condition but no insurance 3. No condition but has insurance 4. no condition and no insurance then used this new variable for a two way table with year variable using code:
proc freq data=mythesis.jdata ;
tables condition_coverage*year_class/ chisq;
weight perweight1;
run;
and got following output:
Table of condition_coverage by year_class | |||
condition_coverage | year_class | ||
Frequency | post | pre | Total |
nocond_hascovera | 3.364E7 | 3.124E7 | 6.488E7 |
nocond_nocoverag | 5818615 | 9618986 | 1.544E7 |
preex_nocoverage | 3492139 | 6198915 | 9691053 |
prex_hascoverage | 3.575E7 | 3.246E7 | 6.821E7 |
Total | 7.87E7 | 7.951E7 | 1.582E8 |
Looks like that solves the question. Will update once i get it verified if this solution is correct. Thanks again.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Looks like a similar question was asked here: https://communities.sas.com/t5/Statistical-Procedures/3-way-cross-tabulations-chi-square-tests/td-p/...
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi, thank you for the reply. I have tried that solution but does not work in my case. It gives me an error message that, "data is not sorted in ascending sequence'. Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Try running this prior to proc freq:
proc sort data=mydata;
by preex_status coverage_status year_Class;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you @unison that definitely helped and I could run the code. But i still got 2 tables. Is there anyway i could get one table like below:
Before | Policy | after | policy | |
Coverage status | Pre-existing condition | No | Pre-existing condition | No |
Yes | ||||
No |
Thank you again 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
What do you want to go in the blank spots?
if it’s just the frequencies then you can use
out=outfreq
On the table statement (next to your chisq option). Then you would do something like this:
proc report data=outfreq;
column sex height, count weight,count;
define sex/group;
define height/across;
define weight/across;
define count/analysis sum;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thanks but that won't work. But i think i might have solved it. I just created a new variable using condition statement and created four categories for the new variable where 1. a person has condition and insurance. 2. Has condition but no insurance 3. No condition but has insurance 4. no condition and no insurance then used this new variable for a two way table with year variable using code:
proc freq data=mythesis.jdata ;
tables condition_coverage*year_class/ chisq;
weight perweight1;
run;
and got following output:
Table of condition_coverage by year_class | |||
condition_coverage | year_class | ||
Frequency | post | pre | Total |
nocond_hascovera | 3.364E7 | 3.124E7 | 6.488E7 |
nocond_nocoverag | 5818615 | 9618986 | 1.544E7 |
preex_nocoverage | 3492139 | 6198915 | 9691053 |
prex_hascoverage | 3.575E7 | 3.246E7 | 6.821E7 |
Total | 7.87E7 | 7.951E7 | 1.582E8 |
Looks like that solves the question. Will update once i get it verified if this solution is correct. Thanks again.