1
votes

Suppose I have a dataset full, and I want to select all variables and put them in the var statement in the proc summary statement. Is there an easy way to do this? How do I select all variables in the select statement?

proc sql noprint; 
    select * into :all separated by " "
    from full;

    %put all = &all.;

    proc summary data=full print;
      *var &list of variables from dataset;
      class type;
      output out=work.summary;
    run; 
2

2 Answers

2
votes

When in doubt, try _NUMERIC_ (or _CHARACTER_ or _ALL_ in other similar situations):

proc means data=sashelp.class;
var _numeric_;
run;

FWIW, your approach was wrong, but there is a similar approach that could work.

proc sql;
select name into :namelist separated by ' '
from dictionary.columns
where libname='WORK' and memname='FULL' and upcase(type)='NUM';
quit;

That goes into the dictionary tables (similar to PROC CONTENTS output datasets) and pulls the variable names into a list.

0
votes

I'd probably just use the default list syntax. Get the order from proc contents and the list first and last variables. For example.....

proc contents data = sashelp.class position;

Assume w is first variable listed and n is the last, then

proc summary data=full print;
      var w--n;
      class type;
      output out=work.summary;
    run; 

Note that you need 2 dashes for this type of list. If you have sequentially numbered variables like x1 x2 x3 x4 x5 etc. You would do

var x1-x5;