DATA Step, Macro, Functions and more

insert all variables of a dataset into one macro variable

Accepted Solution Solved
Reply
Contributor
Posts: 28
Accepted Solution

insert all variables of a dataset into one macro variable


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.


Accepted Solutions
Solution
‎04-15-2013 06:50 PM
Super User
Super User
Posts: 6,497

Re: insert all variables of a dataset into one macro variable

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


All Replies
Valued Guide
Posts: 2,174

Re: insert all variables of a dataset into one macro variable

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

Valued Guide
Posts: 2,174

Re: insert all variables of a dataset into one macro variable

do you want variables or variable values?

Solution
‎04-15-2013 06:50 PM
Super User
Super User
Posts: 6,497

Re: insert all variables of a dataset into one macro variable

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 ;

Contributor
Posts: 28

Re: insert all variables of a dataset into one macro variable

Thank you Tom.

Regular Contributor
Posts: 198

Re: insert all variables of a dataset into one macro variable

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;

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 232 views
  • 0 likes
  • 4 in conversation