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

Greetings, this is my first time using this webpage and I would appreciate if you could help me out. I need to create several linear models like the following:

 

proc glm data=tabla.transpuesto_lluvia plots=none;
	model _9198 =_9446 _9452 _9200;
run;

_9198, _9446, etc. are variables from a database (tabla.transpuesto_lluvia). My problem is that I have over 20 variables to model and I was wondering if I could autome the process with this idea in mind:

proc glm data=tabla.transpuesto_lluvia plots=none;
	model v1 =v2 v3 v4;
run;

These are the combination of variables that I want to model, being the first row the one in the example:

data tabla.correlaciones;
input v1 $ v2 $ v3 $ v4 $;
cards;
_9198 _9446 _9452 _9200
_9952 _9773 _9766 _9717
_9489 _9487 _9477 _9898
_9717 _9766 _9726 _9773
_9822 _9814 _9815 _9862
_9773 _9952 _9766 _9717
_9446 _9452 _9198 _9814
_9913 _9878 _9916 _9874
_9908 _9910 _9898 _9874
_9452 _9946 _9814 _9198
_9898 _9896 _9862 _9874
_9766 _9773 _9952 _9717
_9726 _9717 _9766 _9773
_9815 _9814 _9452 _9200
_9896 _9898 _9487 _9862
_9874 _9898 _9862 _9910
_9910 _9908 _9874 _9878
_9814 _9815 _9452 _9200
_9862 _9898 _9874 _9896
_9477 _9487 _9489 _9898
_9878 _9913 _9916 _9874
_9200 _9452 _9814 _9815
_9916 _9878 _9913 _9874
_9487 _9489 _9477 _9898
;
run;

Any idea of how could I create multiple models thanks to this last combination of variables? Thank you for your time.

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Ok. First off, let us create one PROC GLM step for each combination in the correlaciones data set. You can do this with Call Execute Logic like this.

 

Notice that I have commented out the Call Execute Statement, since I don't have your data. You can see the generated code in the c variable in the Callstack data set. Each model creates an output data set Model+N in the work library. 

 

This should get you started. Feel free to ask 🙂

 

data correlaciones;
input v1 $ v2 $ v3 $ v4 $;
cards;
_9198 _9446 _9452 _9200
_9952 _9773 _9766 _9717
_9489 _9487 _9477 _9898
_9717 _9766 _9726 _9773
_9822 _9814 _9815 _9862
_9773 _9952 _9766 _9717
_9446 _9452 _9198 _9814
_9913 _9878 _9916 _9874
_9908 _9910 _9898 _9874
_9452 _9946 _9814 _9198
_9898 _9896 _9862 _9874
_9766 _9773 _9952 _9717
_9726 _9717 _9766 _9773
_9815 _9814 _9452 _9200
_9896 _9898 _9487 _9862
_9874 _9898 _9862 _9910
_9910 _9908 _9874 _9878
_9814 _9815 _9452 _9200
_9862 _9898 _9874 _9896
_9477 _9487 _9489 _9898
_9878 _9913 _9916 _9874
_9200 _9452 _9814 _9815
_9916 _9878 _9913 _9874
_9487 _9489 _9477 _9898
;
run;

data callstack;
   set correlaciones;
   c = compbl(cat(
   "proc glm data = tabla.transpuesto_lluvia plots=none outstat = model", _N_, ";
      model ", v1, " = ", v2, " ", v3, " ", v4, ";
    run;"
    ));
   *call execute(c);
run;

View solution in original post

5 REPLIES 5
PeterClemmensen
Tourmaline | Level 20

@Devir Hi and welcome to the SAS Community 🙂

 

Sure, this is possible. What is your desired result here? HTML output or SAS data sets?

Devir
Fluorite | Level 6
I need to make some predictions with these models, so I think Im going to need a dataset to work with.
Thank you for your welcome!
PeterClemmensen
Tourmaline | Level 20

Ok. First off, let us create one PROC GLM step for each combination in the correlaciones data set. You can do this with Call Execute Logic like this.

 

Notice that I have commented out the Call Execute Statement, since I don't have your data. You can see the generated code in the c variable in the Callstack data set. Each model creates an output data set Model+N in the work library. 

 

This should get you started. Feel free to ask 🙂

 

data correlaciones;
input v1 $ v2 $ v3 $ v4 $;
cards;
_9198 _9446 _9452 _9200
_9952 _9773 _9766 _9717
_9489 _9487 _9477 _9898
_9717 _9766 _9726 _9773
_9822 _9814 _9815 _9862
_9773 _9952 _9766 _9717
_9446 _9452 _9198 _9814
_9913 _9878 _9916 _9874
_9908 _9910 _9898 _9874
_9452 _9946 _9814 _9198
_9898 _9896 _9862 _9874
_9766 _9773 _9952 _9717
_9726 _9717 _9766 _9773
_9815 _9814 _9452 _9200
_9896 _9898 _9487 _9862
_9874 _9898 _9862 _9910
_9910 _9908 _9874 _9878
_9814 _9815 _9452 _9200
_9862 _9898 _9874 _9896
_9477 _9487 _9489 _9898
_9878 _9913 _9916 _9874
_9200 _9452 _9814 _9815
_9916 _9878 _9913 _9874
_9487 _9489 _9477 _9898
;
run;

data callstack;
   set correlaciones;
   c = compbl(cat(
   "proc glm data = tabla.transpuesto_lluvia plots=none outstat = model", _N_, ";
      model ", v1, " = ", v2, " ", v3, " ", v4, ";
    run;"
    ));
   *call execute(c);
run;
Devir
Fluorite | Level 6
Thanks for your answer! I'll try.
PaigeMiller
Diamond | Level 26

PROC GLM should end with a QUIT; and not a RUN;

--
Paige Miller

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 5 replies
  • 823 views
  • 7 likes
  • 3 in conversation