DATA Step, Macro, Functions and more

Macro text manipulation

Not applicable
Posts: 0

Macro text manipulation

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...

Super Contributor
Super Contributor
Posts: 3,176

Re: Macro text manipulation

Posted in reply to deleted_user
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 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".

Scott Barry
SBBWorks, Inc.
Super Contributor
Posts: 474

Re: Macro text manipulation

Posted in reply to deleted_user
Hello guys.

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 */
proc sort;

/* load NAMEs to myPredictors macro */
%let myPredictors=;
data _null_;
/* build myPredictors list with NAMES separated by space char */
call symput('myPredictors',catx(' ',symget('myPredictors'),NAME));

/* result */
%put &myPredictors;

Greetings from Portugal.

Daniel Santos at
Not applicable
Posts: 0

Re: Macro text manipulation

Posted in reply to DanielSantos
thanks very much, work perfect.
Regards from Horta, Azores, Very nice Islands..
Ask a Question
Discussion stats
  • 3 replies
  • 3 in conversation