turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- General Programming
- /
- expanding a SAS macro for Kruskal–Wallis analysis ...

Topic Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

11-11-2013 12:38 AM

For those who would like to run a Kruskal-Wallis (KW) test on their non-parametric data, followed by a Dunn's post hoc test, Elliott has published a macro KW_MC on this site www.alanelliott.com/kw

Let's say you run the macro KW_MC (Kruskal-Wallis with Multiple Comaprison) on data containing 3 groups (A, B, C). This will produce an overall comparison across the 3 groups (a small table with title **Kruskal-Wallis Test)** and a Dunn's post hoc test in 3 paired comparison (A vs B, B vs C, C vs A, the table on the last page with the title **Kruskal-Wallis Tied Ranks**). This macro works well for data with just one group variable, which is specified by a single global macro variable "GROUP". My data are, however, more complex in that I have 4 grouping variables:

- exp_name (project)
- replicate
- trt_group (groups)
- respType (type of the response variable)

My data are in long-format and all the response variables are grouped into 2 column- one with the type (respType) and the other with the value (respVar).

I would like to run the KW analysis across all the subgroup combinations (**exp_name x respType x trt_group x replicate)** and for each of these combinations run a Dunn's post hoc test between any of the two groups (in **trt_label**). I've tweaked the PROC NPAR1WAY (see **KW_MC.sas) **and results of the overall comparison are output to the dataset 'kw_overall.' However, I got stuck when attempting to modify the codes following the the PROC NPAR1WAY. I didn't even find a dataset that contains the complete statistics of Duntrtn's post hoc (however, these are passed to the RTF file). Can anyone please advise on how to tweak the macro so it can take multiple grouping variables (in my case: exp_name x replicate x trt_group x respType )? Although this question may sound like a statistical one, it is actually more about macro writing skills.

My explanation for each file:

**data.xls**contains a subset of my data**KW_MC.sas**contains Elliott's macro codes. (I've tweaked the PROC NPAR1WAY but leaving the rank part unchanged)**KW_MC_example3.sas**is where the macro is invoked and output is rearranged into a table**sasrtf.rtf**contains the output stored (you can see a KW test is done correctly for each subgroup combination, but Dunn's test, on the last page, is incorrect. It has summed up all the wilcoxon scores and produced just one table)**KW_overall_mbExpansion_someData.rtf**shows the overall comparisons for all the subgroup combinations. The first 3 columns are the grouping variable (**exp_name, respType, replicate; trt_group ignored)**and the last two are statistics of the overall comparison (or**Kruskal-Wallis Test)**. My goal is to merge this table with the Dunn's post hoc results. I am needing help to get the output from the Dunn's test.

Thanks in advance!!

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Chang

11-11-2013 09:08 AM

Some points to consider:

Kruskal-Wallis is set up for a one-way analysis of variance. Multiple levels of a single variable. If you have more than one independent variable, it isn't appropriate. If you have equal replication for all levels, a Friedman test can be applied for a two-way analysis of variance.

So long as you have equal replication in "**exp_name x respType x trt_group x replicate"** for all levels, you could treat it as a one-way analysis (like a means model in GLMMs). However, I don't see the reason for including respType--it seems to code for a response variable, and its inclusion opens up a multivariate approach (which, at least the ranks should overcome)--or replicate, which in the sample data has the same value(=1) for all observations. Create a dummy variable that has all levels of the four-way interaction (3x6x3x1 for the example data) and pass that to the macro. Now, unfortunately I don't remember if rank transformation is well-preserved as far as coming up with main effect and interaction estimates. I know NPAR1WAY doesn't support estimates as in the linear model procs.

I would really consider rank transforming the data prior to analysis, and using PROC GLIMMIX or something similar, to analyze this data.

Steve Denham

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Chang

08-31-2016 11:08 AM

Hello,

I am attempting to run the Dunn Macro package of code right now. I am about half way through but have gotten snagged on a data step. It seems like there are more coming up as well.

data KW_MC_TMP5;set KW_MC_TMP5;

1294 N=_N_;

1295 keep n mean1-mean&groups;

WARNING: Apparent symbolic reference GROUPS not resolved.

ERROR: Missing numeric suffix on a numbered variable list (mean1-mean).

ERROR 22-322: Syntax error, expecting one of the following: a name, ;, _ALL_, _CHARACTER_,

_CHAR_, _NUMERIC_.

ERROR 200-322: The symbol is not recognized and will be ignored.

Is there a way to resolve this? I am relatively new to SAS and trying to learn while using (not highly recommended) but any advice with this will be greatly appreciated.

The upcoming steps have similar synthax.

data KW_MC_TMP6;set KW_MC_TMP6;

N=_N_;

keep n n1-n&groups;

run;

data KW_MC_TMP7;set KW_MC_TMP7;

N=_N_;

keep n gp1-gp&groups;

run;

Thanks!