Statistical programming, matrix languages, and more

corr function with missing values

Reply
Contributor
Posts: 23

corr function with missing values

I'm running a corr function in iml, e.g.,

proc iml;

  use want_ret;

  read all var _NUM_ into x[colname=permno];

  close want_ret;

  corr=corr(x);

  print corr;

quit; run;

Because my data has some missing value I get an execution error - "Invalid argument or operand; contains missing value."

I found this page which seems to suggest that I should be able to compute it with missing values: http://support.sas.com/documentation/cdl/en/imlug/64248/HTML/default/viewer.htm#imlug_langref_sect05...

I thought the syntax would be corr(x,Pearson,pairwise); but that doesn't seem to work either. Any ideas? I'd like the correlation even though I'm missing just a few observations in the time series.

Thanks,

Rick

SAS Super FREQ
Posts: 3,221

Re: corr function with missing values

The CORR function supports missing values:

proc iml;
use sashelp.class;
read all var _NUM_ into X;
X[{1 7 19 32}]=.;
c = corr(x);
print c;
print (countmiss(X,"col"));

In fact, you can have all missing values and hte CORR function still doesn't return an error:


X = j(10,3,.);
c = corr(x);
print c;

This assumes that you are running SAS/IML 9.22 or later. Please copy/paste the EXACT contents of the SAS log.

By the way, if you use optional arguments, be sure to enclose them in quotes

corr(x,"Pearson","pairwise");

as specified in the doc.

Contributor
Posts: 23

Re: corr function with missing values

I appear to be running sas 9.2. If I hit about sas it says SAS 9.2 TS Level 2M2, X64_VSPRO platform. Is that the issue?

thanks,

Rick

Super User
Super User
Posts: 5,960

Re: corr function with missing values

I think that TS2M3 is the stealth SAS/Stat upgrade to 9.22.

Post a Question
Discussion Stats
  • 3 replies
  • 464 views
  • 0 likes
  • 3 in conversation