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

Hi,

 

 

I have been using SAS/IML for few months now. I would like to use different sets of data to undertake some calculations related to Experimental Designs, the only way I am aware of is to import the data from an excel file to be then read into arrays in sas/iml. This way of importing data is making some of the calculations very hard. 

 

Does anyone know the different ways of setting the data to be used particularly in SAS/IML.

 

I want to save different sets of data in files and call them into SAS/IML. Is that possible?

 

Thanks,

DJ

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

Any SAS data set can be used in PROC IML.

 

You can use the PROC IML command USE and the PROC IML command READ to get the SAS data sets into IML.

--
Paige Miller

View solution in original post

9 REPLIES 9
PaigeMiller
Diamond | Level 26

Any SAS data set can be used in PROC IML.

 

You can use the PROC IML command USE and the PROC IML command READ to get the SAS data sets into IML.

--
Paige Miller
DJ20
Obsidian | Level 7

Is it read and used in a similar way as data from an excel file. Is there any advantages of using the SAS data set?

PaigeMiller
Diamond | Level 26

The advantage of using a SAS data set is that it is not an Excel file. But maybe you have something else in mind?

--
Paige Miller
DJ20
Obsidian | Level 7

Thanks for your reply.

 

I had hope that using a different method to import data will make some calculations easier to tackle.

Right now, first I have to import the data from excel then read and assign each column to an array separately. Is there a way to put the whole data set in a matrix at once?

PaigeMiller
Diamond | Level 26

Yes you can read an entire SAS data set into PROC IML as a matrix. Please look at the examples in the documentation that I linked to.

--
Paige Miller
DJ20
Obsidian | Level 7

Thank you very much.

 

I managed to read all the variables into a matrix however I had to read the numerical  _NUM_ and character _CHAR_  variables separately even though I tried using _ALL_ to print all variable into one matrix but its not working. Are you aware of any reasons that can cause such a problem?

 

 

Also, is it possible to read the headings of the columns from excel as well?

PaigeMiller
Diamond | Level 26

Character variables and numeric variables need to be in separate matrices. In PROC IML, you have to refer to a matrix by its matrix name, I don't think you can refer to specific columns by some other name. So maybe most of the data goes into one matrix, and another part of the data goes into a different matrix, allowing you to have somewhat meaningful matrix names.

 

You can change the way matrices are display, to have meaningful column names, but that only affect the display of the matrices and not calculations done with the matrices. https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.4&docsetId=imlug&docsetTarget=imlug_...

 

 

 

 

--
Paige Miller
DJ20
Obsidian | Level 7

Nice one mate. That was very useful. Now my data matrices are looking so much better.

 

 

Thanks you very much,

DJ

Rick_SAS
SAS Super FREQ

For an overview, see "Reading ALL variables INTO a matrix."

 

Paige said, "I don't think you can refer to specific columns by some other name," but that is not actually correct. You can access rows or columns of a matrix by names.  However, maybe what Paige meant is that this feature is not always useful in complex programs, which is an opinion that I agree with.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 9 replies
  • 1055 views
  • 2 likes
  • 3 in conversation