BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ilikesas
Barite | Level 11

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!!!

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

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

2 REPLIES 2
IanWakeling
Barite | Level 11

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;
Rick_SAS
SAS Super FREQ

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."

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

Multiple Linear Regression in SAS

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.

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 2 replies
  • 1013 views
  • 3 likes
  • 3 in conversation