DATA Step, Macro, Functions and more

Macro text manipulation

Reply
N/A
Posts: 0

Macro text manipulation

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

thanks
Super Contributor
Super Contributor
Posts: 3,174

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

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;
run;

/* only necessary if you need to maintain the column order */
proc sort;
by VARNUM;
run;

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

/* result */
%put &myPredictors;

Greetings from Portugal.

Daniel Santos at www.cgd.pt
N/A
Posts: 0

Re: Macro text manipulation

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