How to select a column by its name in PROC IML process?

Accepted Solution Solved
Reply
Contributor
Posts: 31
Accepted Solution

How to select a column by its name in PROC IML process?

Hello to whomever can help

 

I have a data set like following:

Capture.PNG

I tried the following program, but it give me error.

PROC IML;
        print (mu_vec['MSFT']);

error message is like following. Please help. Thank you.

Capture.PNG


Accepted Solutions
Solution
‎01-26-2016 07:36 PM
SAS Super FREQ
Posts: 3,416

Re: How to select a column by its name in PROC IML process?

If you are using a column name attribute, you need to specify the name as a column:
mu_vec[, 'MSFT'];

 

For more information and examples, see "Access rows or columns of a matrix by names."

View solution in original post


All Replies
SAS Super FREQ
Posts: 3,416

Re: How to select a column by its name in PROC IML process?

First you have to read the data from the data set into a matrix or vector.

Read the article "Reading ALL variables INTO a matrix."

 

Is the data in a data set that has one observation and three variables?  If so, then the PROC IML statements look like this:

proc iml;
use Have;
read all var {"MSFT" "NORD" "SBUX"} into mu_vec;
close Have;

If you want to read all of the numeric variables, you can use this:

 

read all var _NUM_ into mu_vec[colname=varNames];
Contributor
Posts: 31

Re: How to select a column by its name in PROC IML process?

Hello Rick

Thank you for your response and help.

Data was create in PROC IML procedure.

It is like following code:

names = {'MSFT' 'NORD' 'SBUX'};
mattrib mu_vec c=names;

actually I haven't tried the following.

mu_vec[, 'MSFT'];
Solution
‎01-26-2016 07:36 PM
SAS Super FREQ
Posts: 3,416

Re: How to select a column by its name in PROC IML process?

If you are using a column name attribute, you need to specify the name as a column:
mu_vec[, 'MSFT'];

 

For more information and examples, see "Access rows or columns of a matrix by names."

☑ This topic is SOLVED.

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

Discussion stats
  • 3 replies
  • 316 views
  • 1 like
  • 2 in conversation