I need to combined into a single string the names of variable in a data set to use in a model as predictors, for example data A has variable Name with observations:
1 Year 2 Temp 3 Color 4 pH. I want to create a macro variable string like
%let myPredictors = Year Temp Color pH; so when using a model formula simply type
model myY = &myPredictors / ; of course I will be working with >50 variables, and possible different ones each time...
Explore using SAS PROC SQL and the SAS-maintained view DICTIONARY.COLUMNS -- you can create a SAS macro variable then reference the macro variable that contains your SAS column (dataset variable) names to resolve your variable list/string.
Visit the SAS support http://support.sas.com/ website and use the SEARCH facility to find conference papers and other SAS-provided documentation and code samples on the search argument "proc sql dictionary columns generate macro variable".
DICTIONARY.COLUMNS would be the most simple and straightforward way.
I still prefer the PROC CONTENTS procedure, since when using it intensively (many columns, many tables) it is a lot more fast against the querying DICTIONARY tables method.
I think this will do what you need:
proc contents data = A out = _A_CONTENTS noprint;
/* only necessary if you need to maintain the column order */
/* load NAMEs to myPredictors macro */
/* build myPredictors list with NAMES separated by space char */
call symput('myPredictors',catx(' ',symget('myPredictors'),NAME));