BookmarkSubscribeRSS Feed
FREDY_07
Fluorite | Level 6
Hi, I would like to create a model by using input x which is a matrix and output y which is a vector. I saw several examples for GLM but using input variables x1 ,x2,.. so on. But I have one variable x which is a matrix. Many thanks.
20 REPLIES 20
Reeza
Super User

If you have matrix, you may want to look at IML.

 

Otherwise, post a sample of what your data looks like.

 

Unless your matrix is Nx1, it's likely your data structure will support GLM.  

Rick_SAS
SAS Super FREQ

Could you describe your data further? How does the matrix enter into the model?

 

FREDY_07
Fluorite | Level 6
I have 55 input variables in the data and 20 samples. so its 20*55. and y is a 1*55 matrix. so it is a vector. Many thanks for helping.
FREDY_07
Fluorite | Level 6
I am so sorry y is a 1*20 matrix.
Reeza
Super User

Are your matrices SAS data sets - .sas7bdat files?

FREDY_07
Fluorite | Level 6

No. It is a csv file.

Reeza
Super User

Please post a sample of your data. I think you can use proc glm. 

FREDY_07
Fluorite | Level 6

I attached the data. There are 20 samples and 55 variables in the data. here is the output: Many thanks.

8.145.775.894.784.483.965.15.575.274.25.232.944.774.674.85.215.283.914.215.17
Reeza
Super User

This is how the code could look, if you wanted a simple GLM model:

 

*import dataset into SAS;
data have;
infile 'C:\_localdata\data.csv' dlm="," dsd truncover lrecl=1000;
informat var1-var40 best32.;
format var1-var40 best32.;
input var1-var40;
run;

*Run model;
proc glm data=have;
	model var1 = var2--var40;
run;quit;
FREDY_07
Fluorite | Level 6

Many thanks for your response. I have some questions for you. Where is the output variable 'y'. Also why did you take 40 variables is there a specific reason for that?

Reeza
Super User

Your file had 40 variables, it was a demo of how it could be accomplished.

It had no headers so I don't know which is y, which is x etc. 

 

I simply took the first variable as the Y and the remaining as X to demonstrate the GLM procedure.

To develop a final model you might want to use a selection method to subset the variables. PROC GLMSELECT is helpful here.

 

Please consider my code a sample, not what you should do. You should know what your variables are and how they should be handled.  

 

 

FREDY_07
Fluorite | Level 6

Many thanks for your response I understood you mean.

My bad. Mistakengly I put 55*40 input. It should be 55*20 but I see you mean. The 40 is the sample number. I do have 55 variables so is the following right?

 

proc glm data=have;
	model y = var1--var55;
run;quit;

 I don't now what GLMSLECT is doing at the final stage. I will research for it. Many thanks for your responses.

Reeza
Super User

You had 55 observations, not variables. 

 

The columns are variables not rows

 

In general, your code looks correct, assuming that matches your data structure.

FREDY_07
Fluorite | Level 6

Thank you so much so I need to transpoze my data in order to make right model. Many thanks.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 20 replies
  • 2409 views
  • 3 likes
  • 4 in conversation