Programming the statistical procedures from SAS

GLM

Reply
Occasional Contributor
Posts: 11

GLM

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.
Super User
Posts: 18,586

Re: GLM

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.  

SAS Super FREQ
Posts: 3,551

Re: GLM

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

 

Occasional Contributor
Posts: 11

Re: GLM

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.
Occasional Contributor
Posts: 11

Re: GLM

I am so sorry y is a 1*20 matrix.
Super User
Posts: 18,586

Re: GLM

Are your matrices SAS data sets - .sas7bdat files?

Occasional Contributor
Posts: 11

Re: GLM

No. It is a csv file.

Super User
Posts: 18,586

Re: GLM

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

Occasional Contributor
Posts: 11

Re: GLM

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
Super User
Posts: 18,586

Re: GLM

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;
Occasional Contributor
Posts: 11

Re: GLM

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?

Super User
Posts: 18,586

Re: GLM

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.  

 

 

Occasional Contributor
Posts: 11

Re: GLM

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.

Super User
Posts: 18,586

Re: GLM

You had 55 observations, not variables. 

 

The columns are variables not rows

 

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

Occasional Contributor
Posts: 11

Re: GLM

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

Ask a Question
Discussion stats
  • 20 replies
  • 723 views
  • 3 likes
  • 4 in conversation