DATA Step, Macro, Functions and more

Proc Means - Customising Output

Posts: 53

Proc Means - Customising Output



Need to change the proc means output.


Here is the actual output:


proc  means data=test mean median sum;

class countryname ;

var income ;



Country NameN ObsMeanMedianSum


There is another variable called Gender, which has male and female. I need the output to be like this showing only the nobs (counts) instead of displaying statistics for male and female. I dont want to include gender in the class variable to avoid the statistics for the male and female.


Country NameMaleFemaleN ObsMeanMedianSum



As you can see in this output(Which I need), there is no stats for male and female.


Thanks for looking

Super User
Posts: 17,831

Re: Proc Means - Customising Output

You can't do this via PROC MEANS as far as I know. The easiest alternative is to calculate it externally and merge the data in. 


Depending on how complex your report is, you could generate the table in one step in SQL but it's a fairly manual task. And you would need SAS 9.4+ at least. 

Super User
Super User
Posts: 7,401

Re: Proc Means - Customising Output

proc  means data=test mean median sum;
  class countryname ;
  var income ;
  output out=inter;
proc sql;
  create table WANT as
  select  COUNTRYNAME,
          (select count(*) from TEST A where A.COUNTRYNAME=COUNTRYNAME and SEX="MALE") as MALE,
          (select count(*) from TEST A where A.COUNTRYNAME=COUNTRYNAME and SEX="FEMALE") as FEMALE,
   from   INTER;
Super User
Posts: 9,681

Re: Proc Means - Customising Output

If you have SAS9.4 . Try SQL.


proc sql;
select age,count(*) as n,
 mean(weight) as mean,
 median(weight) as median,
 sum(weight) as sum,
 (select count(*) from sashelp.class where sex='F' and age=a.age) as Female,
 (select count(*) from sashelp.class where sex='M' and age=a.age) as Male

 from sashelp.class as a
  group by age ;
Super User
Posts: 10,500

Re: Proc Means - Customising Output

Provide some data.

I suspect that Proc Tabulate and/or Proc report could do that quite easily.


A complete guess without data:


proc tabulate data = have;

   class country;

   class gender;

   var income;

   table country,

            (gender=' ' All='N obs')*n=' ' income=' '*(mean*f=dollar12.2 median*f=dollar12.2 sum*f=dollar16.2);


Ask a Question
Discussion stats
  • 4 replies
  • 1 like
  • 5 in conversation