BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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
3 REPLIES 3
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.
DanielSantos
Barite | Level 11
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
deleted_user
Not applicable
thanks very much, work perfect.
Regards from Horta, Azores, Very nice Islands..
obrigado

sas-innovate-white.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.

 

Early bird rate extended! Save $200 when you sign up by March 31.

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1208 views
  • 0 likes
  • 3 in conversation