BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
drteju
Fluorite | Level 6

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:

 PrePost
Coverage statusPre-existing conditionNoPre-existing conditionNo
Yes    
No    

 

Is this possible or am I using the wrong statistical test? Can someone help me solve it? Thank yo

1 ACCEPTED SOLUTION

Accepted Solutions
drteju
Fluorite | Level 6

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
Percent
Row Pct
Col Pct

post

pre

Total

nocond_hascovera

3.364E7
21.26
51.85
42.74

3.124E7
19.74
48.15
39.28

6.488E7
41.01


nocond_nocoverag

5818615
3.68
37.69
7.39

9618986
6.08
62.31
12.10

1.544E7
9.76


preex_nocoverage

3492139
2.21
36.03
4.44

6198915
3.92
63.97
7.80

9691053
6.13


prex_hascoverage

3.575E7
22.60
52.41
45.43

3.246E7
20.52
47.59
40.82

6.821E7
43.11


Total

7.87E7
49.74

7.951E7
50.26

1.582E8
100.00

 



 

Looks like that solves the question. Will update once i get it verified if this solution is correct. Thanks again. 

View solution in original post

6 REPLIES 6
drteju
Fluorite | Level 6

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.

unison
Lapis Lazuli | Level 10

Try running this prior to proc freq:

proc sort data=mydata;
by preex_status coverage_status year_Class;
run;
-unison
drteju
Fluorite | Level 6

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:

 BeforePolicyafterpolicy
Coverage statusPre-existing conditionNoPre-existing conditionNo
Yes    
No    

Thank you again 🙂

unison
Lapis Lazuli | Level 10

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;
-unison
drteju
Fluorite | Level 6

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
Percent
Row Pct
Col Pct

post

pre

Total

nocond_hascovera

3.364E7
21.26
51.85
42.74

3.124E7
19.74
48.15
39.28

6.488E7
41.01


nocond_nocoverag

5818615
3.68
37.69
7.39

9618986
6.08
62.31
12.10

1.544E7
9.76


preex_nocoverage

3492139
2.21
36.03
4.44

6198915
3.92
63.97
7.80

9691053
6.13


prex_hascoverage

3.575E7
22.60
52.41
45.43

3.246E7
20.52
47.59
40.82

6.821E7
43.11


Total

7.87E7
49.74

7.951E7
50.26

1.582E8
100.00

 



 

Looks like that solves the question. Will update once i get it verified if this solution is correct. Thanks again. 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 6 replies
  • 693 views
  • 1 like
  • 2 in conversation