Yes, you can use a %DO loop within a macro for this.
I'm not familiar with PROC GLM, but maybe there is a way to run the PROC just once for all variables, which might save some processing time if the source table is big. Maybe you have to transpose the table it first.
Thanks for your responses. I think this could work if the variables were named x1, x2, x3, etc.
But, what if they are named height, width, volume, mass, etc. I'm looking for something that will work like proc means. If you specify variables, it will only run those variables. If you don't specify variables, it will run all variables in the dataset.
Is there an "internal" variable name in a dataset other than the name specified in the data statement that can be accessed? Perhaps it looks like x1, x2, x3, etc.
Believe it or not, the answer is yes. I just received an Excel speadsheet that has 218 columns. The first column represents the group. They want the glm procedure with class=group on the 217 remaining variables.
I did it by brute force: a separate call for each variable. I figured there was an easier way to do this for the next time.
In GLM you can use a list of variables or a "SAS Variable List" as the dependents in the model statement.
A "SAS Variable List" is a special way of referring to a list of variables. See docs for details but some are _CHAR_ _NUMERIC_ _ALL_ plus enumerate variable lists x1-x10 or variable range lists. You could use _NUMERIC_ of GROUP is a character or a range list as hight--mass as in the example you specified above.
Probably the easiset is to make GROUP character and specify
model _numeric_ = group;
Look at the docs to learn the details of this very powerfull SAS feature.
Message was edited by: data _null_;
This seems to work. The numbers are the same but the order of the output is a bit different. I don't mind. They have other problems to correct: i.e 217 variables and 300 records. Also, they can adapt to the new output order.
GLM will group the dependents by missing values. The maintain the order of the specified in the MODEL transpose the data and use a BY statement.
dm 'clear log; clear output;';
if _n_ in (2,3) then height=.;
proc contents varnum short;
model _numeric_ = sex;
* To maintain variable order
2) establish variable order
4) use BY statement in GLM
proc transpose data=class out=tall(rename=(col1=y));
by name sex; *unique ID for each row;
var _numeric_; *the default;
proc transpose data=class(obs=0) out=vorder;
data vorder(keep=_name_ vorder index=(_name_));
vorder + 1;
set vorder key=_name_/unique;
by _name_ /*_label_*/ notsorted;
model y = sex;