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

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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