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!!!
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."
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;
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."
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.
Find more tutorials on the SAS Users YouTube channel.