Statistical programming, matrix languages, and more

Read dataset into PROC IML

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 7
Accepted Solution

Read dataset into PROC IML

Hello.

 

I want to read a dataset with two columns into proc iml, but it only prints one column when I print it.

 

Can someone tell me what I am doing wrong please?

proc iml;
        use data.lossdata;
	read all var {lob loss} into A[colname = varNames];
	print A;
quit;

Accepted Solutions
Solution
‎05-21-2017 07:37 AM
SAS Super FREQ
Posts: 3,477

Re: Read dataset into PROC IML

You can read the variables into vectors:

read all var {lob loss};

 

For more information about reading numeric and character variables, see

How to read data set variables into SAS/IML vectors

Reading ALL variables INTO a matrix

View solution in original post


All Replies
Super User
Posts: 9,681

Re: Read dataset into PROC IML

These two variables have the same type ? both are numeric or character ?

Occasional Contributor
Posts: 7

Re: Read dataset into PROC IML

The lob is a character and loss numeric.

Frequent Contributor
Posts: 137

Re: Read dataset into PROC IML

@Ksharp has diagnosed the problem correctly, as matrices are either all character or all numeric.  Whenever you run code, it is always good to check the SAS log for messages, as I suspect you have missed a warning message about a type missmatch.

 

Also check the recent thread on this forum called "Matrix with strings in IML", in particular the link that Rick gives to the Table structure.

Solution
‎05-21-2017 07:37 AM
SAS Super FREQ
Posts: 3,477

Re: Read dataset into PROC IML

You can read the variables into vectors:

read all var {lob loss};

 

For more information about reading numeric and character variables, see

How to read data set variables into SAS/IML vectors

Reading ALL variables INTO a matrix

Occasional Contributor
Posts: 7

Re: Read dataset into PROC IML

[ Edited ]

Thank you all. 
I appreciate the help.

There is still a lot to learn.

SAS Super FREQ
Posts: 3,477

Re: Read dataset into PROC IML

Yes, there is always more to learn, but to get started you might try some of the tips at "Ten tips for learning the SAS/IML language", especially the SAS Global Forum paper  "Getting Started with the SAS/IML Language" (Wicklin 2013)

☑ This topic is SOLVED.

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

Discussion stats
  • 6 replies
  • 268 views
  • 5 likes
  • 4 in conversation