BookmarkSubscribeRSS Feed
ginak
Quartz | Level 8

Hello,

I have a bunch of variables but I'll just focus on 3 here. So for example, I have two cities CITYA and CITYB. I am looking at differences between education levels and ethnicities of providers in CITYA vs. CITYB. So the provider is either in one or the other, so both are dichotomous variables. ethnicity is a categorical variable (1=Caucasian, 2=African American, etc.). I have education level, which is categorical (1=college, 2= graduate school, etc.)

For simplicity sake, here is just the table of city by ethnicity:

proc tabulate data=h.april17;

class city ethnicity;

format ethnicity ethnicity.;

table city all, (ethnicity='ethnicity (count)' all)*n*f=4. (ethnicity='ethnicity%' all)*PCTN/BOX='spa by ethnicity';

run;

proc freq data=h.april17; title 'chisquare: city by ethnicity';tables city*ethnicity/chisq;run;

So what I end up getting is a table with the counts and the percentages. then I ran the proc freq to get the chi-square p-value. However, I'd like to produce a table with a column on the side with the chi-square test statistic as well as the p-value. How may I do this? I really wanted a word document with a big, simple table that's easy to read however I'm not sure how to do that (I'd need a macro?) so for now I'm trying this.

Thanks!

2 REPLIES 2
Bill
Quartz | Level 8

Perhaps you could have tabulate and freq each output a dataset and then merge them together into one dataset.  From there, a simple proc print via ods rtf should take it most of the way ...

ballardw
Super User

You only need a macro if you are going to reuse with different data sets and variables that you would pass by parameter.
Since the CHISQ results actually are going to give you ONE p-value for city*ethnicity I'm not sure that you gain much by having a "column" added to a table.

I have done something remotely similar and I used an output data set from FREQ, (add a line like Output out=<your dataset name> chisq; ) and extracted the statistics I wanted into a macro variable that I used in POSTTEXT statement with the tabulate to create a short sentence immediately after the table.

Something like:

Data _null_;

     set <chisq output dataset name>;

     length string $ 300; /* or however long a phrase you may want*/

     If p_chi le <your critical value> then string="The distribution of ethnicities varies significantly between cities with a p-value of "||strip(put(p_chi,z6.4))||".";

     Else string="There was no statistically significant difference detected";

     Call symput ("Pstring",string);

end;

and in your tablulate code after the BOX= add something like: style={posttext="&pstring"}

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 2 replies
  • 7076 views
  • 1 like
  • 3 in conversation