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
- /
- Base SAS Programming
- /
- Calculation of medcouple

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

03-22-2018 03:09 AM

I am looking for SAS code to calculate the medcouple, has anyone such knowledge?

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

Posted in reply to AlexeyS

03-22-2018 08:28 AM

It is my first time to hear this term. I don't know if @Rick_SAS could write some IML code to make it happen.

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

Posted in reply to Ksharp

03-22-2018 08:53 AM

Unfortunately, I need it in SAS BASE, and not in SAS IML.

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

Posted in reply to AlexeyS

03-22-2018 08:58 AM

I am familiar with this concept, but I do not have any non-IML code to share.

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

Posted in reply to AlexeyS

a month ago

Here's the brute force way. I.e. it doesn't take advantage of the "fast" algorithm in the Wikipedia reference. so it won't scale well against larger datasets.

The example finds the medcouple stat for variable CLOSE in sashelp.stocks for IBM stocks (N=233). If you have a test data set to confirm correctness of the algorithm, I'd suggest running it.

```
data have (keep=date close);
set sashelp.stocks;
where stock='IBM';
run;
proc means data=have noprint;
output out=median median=median;
var close;
run;
data vneed (keep=h) / view=vneed;
set have end=end_of_have;
if _n_=1 then set median;
array upper{2000} _temporary_; /* distance of upper obs to median*/
array lower{2000} _temporary_; /* distance of lower obs to median*/
if close>=median then do;
P+1;
upper{p}=close-median;
end;
if close<=median then do;
Q+1;
lower{q}=median-close;
end;
if end_of_have;
do i=1 to P;
do j=1 to Q;
if upper{i}=0 and lower{j}=0 then h=sign(P-1-i-j);
else h= (upper{i}-lower{j})/(upper{i}+lower{j});
output;
end;
end;
run;
proc means data=vneed median; var h;
run;
```