## Reading an external file (excel) file into SAS-IML to create a matrix

Solved
Occasional Contributor
Posts: 11

# Reading an external file (excel) file into SAS-IML to create a matrix

I have a data set with more than 100 observations and contains three variables, var(x1), var(x2), and cov(x1, x2) in an excel file. How do I read this data set into SAS or SAS-IML to create a 2X2 matrix  with the variances on the diagonal and covariance off diagonal? I'm new to SAS and SAS-IML, and so, does anyone know of a "do-loop" to read these data into a matrix. Any help will be appreciated!

Thanks,

Rommel

Accepted Solutions
Solution
‎02-19-2013 05:59 PM
Occasional Contributor
Posts: 11

## Re: Reading an external file (excel) file into SAS-IML to create a matrix

Hi Sir Sylvain! Sorry if I had to ask you a more specific question related to the question I earlier asked. This is what my problem is:

I'm meta-analyzing effect sizes from more than 100 studies. Some studies have one effect size, or 2 effect sizes, or 3 effect sizes, and etc.

Because studies have different number of effect sizes, the covariance matrices of effect sizes are then different for each study.

To illustrate, I have small data set below (where Study 1 has 2 effect sizes, thus it has a 2X2 covariance matrix; Study has 3 effect sizes, thus

it has a 3X3 covariance matrix; and Study 1 (has 2 missing effect sizes) so it has only 1X1 covariance matrix). So here is my question Sir,

is there a code I can use to (automate) import the covariance matrix from say SAS to SAS-IML without having to type this covariance matrices

into SAS-IML, given the fact that I have more than 100 studies?

Study 1 = { .022 .009,

.009 .023}

Study 2 = { .016 .003 .006,

.003 .016 .008

.006 .008 .016}

Study = { .019}

Thanks so much for the help. I'm new with SAS and SAS IML and I really need to figure out

how I can import my data (covariance matrices) in order for me to run an analysis.

Sincerely,

Rommel

All Replies
SAS Employee
Posts: 1

## Re: Reading an external file (excel) file into SAS-IML to create a matrix

Hello,

SAS/IML comes with an interface: SAS/IML Studio. It implements IMLPlus, an enhanced version of the SAS/IML programming language.

In IMLPlus, you could use the DataObject.CreateFromExcelFile method in a program to read your MS Excel worksheet into SAS/IML Studio.

Otherwise, if you have the SAS/Access to PC Files module, you can use Proc IMPORT to import your MS Excel worksheet into a SAS dataset.

After, in SAS/IML, you can leverage the USE statement to open the dataset and make it current for input, then the READ statement to transfer the data from the dataset to a matrix.

Once in a matrix, you can manipulate the elements as you see fit.

Cheers!

Sylvain

Solution
‎02-19-2013 05:59 PM
Occasional Contributor
Posts: 11

## Re: Reading an external file (excel) file into SAS-IML to create a matrix

Hi Sir Sylvain! Sorry if I had to ask you a more specific question related to the question I earlier asked. This is what my problem is:

I'm meta-analyzing effect sizes from more than 100 studies. Some studies have one effect size, or 2 effect sizes, or 3 effect sizes, and etc.

Because studies have different number of effect sizes, the covariance matrices of effect sizes are then different for each study.

To illustrate, I have small data set below (where Study 1 has 2 effect sizes, thus it has a 2X2 covariance matrix; Study has 3 effect sizes, thus

it has a 3X3 covariance matrix; and Study 1 (has 2 missing effect sizes) so it has only 1X1 covariance matrix). So here is my question Sir,

is there a code I can use to (automate) import the covariance matrix from say SAS to SAS-IML without having to type this covariance matrices

into SAS-IML, given the fact that I have more than 100 studies?

Study 1 = { .022 .009,

.009 .023}

Study 2 = { .016 .003 .006,

.003 .016 .008

.006 .008 .016}

Study = { .019}

Thanks so much for the help. I'm new with SAS and SAS IML and I really need to figure out

how I can import my data (covariance matrices) in order for me to run an analysis.

Sincerely,

Rommel

🔒 This topic is solved and locked.