kingledion
kingledion

Reputation: 2500

How to PROC PRINT only the sum of a column of data

In SAS, you can use PROC PRINT to sum a column and display the sum:

proc print data = dataset.project_out;
    sum variable;
run;

How can I get this function to only print the sum line and not the rest of the data?

Upvotes: 1

Views: 5443

Answers (1)

Joe
Joe

Reputation: 63424

I don't think you can do it with proc print. The closest you can come is the empty var statement:

proc print data=sashelp.class;
  var ;
  sum age;
run;

But sum adds the sum variable to the var list.

You can certainly accomplish this a number of other ways.

PROC SQL is the one I'd use:

proc sql;
  select sum(Age) from sashelp.class;
quit;

PROC REPORT, often called "pretty PROC PRINT", can do it also:

proc report data=sashelp.class;
  columns age;
  define age/analysis sum;
run;

PROC TABULATE can do it:

proc tabulate data=sashelp.class;
  var age;
  tables age*sum;
run;

PROC MEANS:

proc means data=sashelp.class sum;
  var age;
run;

Etc., plenty of ways to do the same thing.

Upvotes: 3

Related Questions