Statistical programming, matrix languages, and more

inputing many variables into proc iml

Accepted Solution Solved
Reply
Super Contributor
Posts: 441
Accepted Solution

inputing many variables into proc iml

Hi,

 

suppose that I have a data of daily stock returns and I have many stocks, say 100. What I want to do is to input all of these stock returns into Proc IML in the following way:

 

Proc IML;
use returns;
read all var {abc def .... zzz} into RMAT;

 

 

So instead of individually typing inside the parentheses the names of the stocks, I would like to have a way that automatically inputs all the 100 names.

 

For the sake of SIMPLICITY consider this as my original data (having only 3 stocks) :

 

data returns;

input abc def zzz;

datalines;

10 2 5

3 -5 7

-1 -7 6

1 3 -2

;

run;

 

And what I would like to have is:

 

Proc IML;
use returns;
read all var {abc def  zzz} into RMAT;

 

But the names should be input automatically and not typed one by one.

I tried doing {abc - zzz} but got an error message...

 

Thank you very much!!!


Accepted Solutions
Solution
‎10-28-2015 10:41 PM
SAS Super FREQ
Posts: 3,752

Re: inputing many variables into proc iml

I agree with Ian. If you also want the names of the variables that you read, you can include the clause [colname=varNames] after the name of the matrix, like this:

read all var _num_ into RMAT[colname=varNames];

The varNames vector is a character vector that contains the name of the variables in the same order as the columns of RMAT.

 

For more details and examples, see the article "Reading ALL variables INTO a matrix."

View solution in original post


All Replies
Frequent Contributor
Posts: 147

Re: inputing many variables into proc iml

Here are two ways to do this.

 

If you want to read all the numeric variables from the input data set then use the syntax:

 

use returns;
read all var _num_  into RMAT;

Or if you use a consistent system for naming variables in the stock returns data set.  For example use s1 s2 and s3 instead of abc def and zzz, then you can read the variables using the syntax:

 

use returns;
read all var ('s1':'s3') into RMAT;
Solution
‎10-28-2015 10:41 PM
SAS Super FREQ
Posts: 3,752

Re: inputing many variables into proc iml

I agree with Ian. If you also want the names of the variables that you read, you can include the clause [colname=varNames] after the name of the matrix, like this:

read all var _num_ into RMAT[colname=varNames];

The varNames vector is a character vector that contains the name of the variables in the same order as the columns of RMAT.

 

For more details and examples, see the article "Reading ALL variables INTO a matrix."

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 304 views
  • 3 likes
  • 3 in conversation