SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mano
Calcite | Level 5


Hi,

For ex:- there are 16 variables in x dataset. If we use proc contents , we can see all the variables in the output window.

But, if I want to insert all these variables into one single macro variable, is there any way.

If i call that macro variable, we need to get all the 16 variables.

Any help is appreciated.

Thanks in advance,

Mano.

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

If you want the variable names separated by spaces you get that from the output of PROC CONTENTS.

proc contents data=x noprint out=contents; run;

proc sql noprint ;

select name into :varlist separated by ' '

from contents ;

quit;

%put Variables are: &varlist ;

View solution in original post

5 REPLIES 5
Peter_C
Rhodochrosite | Level 12

do you want any kind of delimiter, like for the heading of a CSV file?

Peter_C
Rhodochrosite | Level 12

do you want variables or variable values?

Tom
Super User Tom
Super User

If you want the variable names separated by spaces you get that from the output of PROC CONTENTS.

proc contents data=x noprint out=contents; run;

proc sql noprint ;

select name into :varlist separated by ' '

from contents ;

quit;

%put Variables are: &varlist ;

mano
Calcite | Level 5

Thank you Tom.

Ron_MacroMaven
Lapis Lazuli | Level 10

skip the contents

%let Lib_Data = sashelp.class;

PROC SQL; select Name

            into :List_names separated by ' '

          from   dictionary.columns

          where  Libname eq "%upcase(%scan(&Lib_Data,1,.))"

            and  Memname eq "%upcase(%scan(&Lib_Data,2,.))"

            ;

          quit;

%put note: list_names = &List_names;

sas-innovate-wordmark-2025-midnight.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. Sign up by March 14 for just $795.


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
  • 5 replies
  • 1288 views
  • 0 likes
  • 4 in conversation