Hi,
I calculated a chi²-test by running proc freq with this code:
proc freq data=sashelp.cars;
table type*Origin /cellchi2 chisq expected deviation STDRES;
where type <>"Hybrid" and type<>"Truck";
run;
...and got this result:
The result shows: The differences are significant.
Question 1: Now I want to know, where are the biggest/lowest differences between the expected and the observed values. There it would be helpful, to colorize all the values of the row "deviation". For example like in Excel "conditional formatting". For example, I want the numbers to become greener the larger the number. Is there a option for this?
Question 2: Because I want to know, which cells are the reason for this chi²-result, Ive choosen the output incl "STDRES". With these standardized residuals, I want to find out which cells indicate particularly striking differences. But I cant find them in my result. Ive red, that I have to use "crosslist" like this:
proc freq data=sashelp.cars; table type*Origin /crosslist cellchi2 chisq expected deviation STDRES; where type <>"Hybrid" and type<>"Truck"; run;
The design is much different from the other I want. Therefore my question: How can I display the STDRES-Values as additional Row within the first output?
Thank you for helping again!
Better post it at Stat Forum:
https://communities.sas.com/t5/Statistical-Procedures/bd-p/statistical_procedures
and calling @StatDave
A quick and easy way is to just save the CROSSLIST table and then plot it as a heat map in PROC SGPLOT. For example
proc freq data=mydata;
table row*col / chisq crosslist(stdres);
ods output crosslist=clist;
run;
proc sgplot data=clist;
heatmapparm y=col x=row colorresponse=stdresidual;
run;
@Konkordanz wrote:
Hi,
I calculated a chi²-test by running proc freq with this code:
proc freq data=sashelp.cars; table type*Origin /cellchi2 chisq expected deviation STDRES; where type <>"Hybrid" and type<>"Truck"; run;
...and got this result:
The result shows: The differences are significant.
Question 1: Now I want to know, where are the biggest/lowest differences between the expected and the observed values. There it would be helpful, to colorize all the values of the row "deviation". For example like in Excel "conditional formatting". For example, I want the numbers to become greener the larger the number. Is there a option for this?
Question 2: Because I want to know, which cells are the reason for this chi²-result, Ive choosen the output incl "STDRES". With these standardized residuals, I want to find out which cells indicate particularly striking differences. But I cant find them in my result. Ive red, that I have to use "crosslist" like this:
proc freq data=sashelp.cars; table type*Origin /crosslist cellchi2 chisq expected deviation STDRES; where type <>"Hybrid" and type<>"Truck"; run;
The design is much different from the other I want. Therefore my question: How can I display the STDRES-Values as additional Row within the first output?
Thank you for helping again!
Generic response to "how to combine output": Use the ODS OUTPUT option for the results tables to get the different tables present in the results as data sets. Then combine them and use a different reporting procedure, Print, Report or Tabulate to display the desired results.
The documentation for Proc Freq (and practically every procedure that generates ODS output) will have the ODS Table names in the details section of the online help.
HOW to combine them depends on what the desired appearance will be. Also, be aware that the content of those data sets will likely differ from the way displayed in results to meet data set requirements such as single variable of given name.
Your code generates this log:
23 proc freq data=sashelp.cars; 24 table type*Origin /cellchi2 chisq expected deviation STDRES; 25 where type <>"Hybrid" and type<>"Truck"; NOTE: The "<>" operator is interpreted as "not equals". 26 run; NOTE: Writing HTML Body file: sashtml.htm WARNING: The STDRES option is available only with the CROSSLIST option.
Which means you cannot get what you are requesting unless you add the CROSSLIST option to the table statement.
If you want to find the largest, smallest or compare any of the results in the the results the ODS OUTPUT created data sets is likely what you want to use to search in as well.
proc freq data=sashelp.cars; ods output crosslist =mycrosslistdata chisq =mychisqdata ; table type*Origin /crosslist cellchi2 chisq expected deviation STDRES; where type <>"Hybrid" and type<>"Truck"; run;
Caution: use of the <> as a comparison has different meanings in some places where it is a MAX operator. So you may want to use NE for 'not equal'. To save some typing you might consider:
where type not in ('Hybrid' 'Truck');
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.