DATA Step, Macro, Functions and more

keeping variables of a dataset into a varlist

Reply
Contributor
Posts: 60

keeping variables of a dataset into a varlist

I usually use this in order to create a varlist

%let varlist=var1 var2 var3;

I call the varlist by using &varlist

I have a dataset with 4000 variables that I would like to keep into a varlist as well without entering them one by one in the %let statement

Any idea on how to do this?
PROC Star
Posts: 7,492

Re: keeping variables of a dataset into a varlist

Posted in reply to sasuser1000
Yes you can, but why? What are you trying to do as variables are automatically kept unless you explicitly drop them?

You can always use proc sql on dictionary.columns to automatically create a macro variable that contains the kind of list you describe.

Art
Contributor
Posts: 60

Re: keeping variables of a dataset into a varlist

Hi Art297,

do you mean doing this?

proc sql;
select a.* into:varlist2
from class as a;
quit;
PROC Star
Posts: 7,492

Re: keeping variables of a dataset into a varlist

Posted in reply to sasuser1000
No. Assuming by class you meant sashelp.class, then what I meant was:
[pre]
proc sql noprint;
select name
into :varlist2 separated by " "
from dictionary.columns
where libname eq "SASHELP" and
memname="CLASS"
;
quit;
[/pre]

Art
Ask a Question
Discussion stats
  • 3 replies
  • 357 views
  • 0 likes
  • 2 in conversation