BookmarkSubscribeRSS Feed
Kalai2008
Pyrite | Level 9

Hello,

 

Need to change the proc means output.

 

Here is the actual output:

 

proc  means data=test mean median sum;

class countryname ;

var income ;

run;

 

Country NameN ObsMeanMedianSum
Algeria60$3,676.36$181.94$222,764.00
Afghanistan64$18,169.66$6,056.50$119,997.97

 

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
Algeria233760$3,676.36$181.94$222,764.00
Afghanistan244064$18,169.66$6,056.50$119,997.97

 

 

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

 

Thanks for looking

4 REPLIES 4
Reeza
Super User

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. 

RW9
Diamond | Level 26 RW9
Diamond | Level 26
proc  means data=test mean median sum;
  class countryname ;
  var income ;
  output out=inter;
run;
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,
          NOBS,
          MEAN,
          MEDIAN,
          SUM
   from   INTER;
quit;
Ksharp
Super User

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 ;
 quit;
ballardw
Super User

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);

run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 813 views
  • 1 like
  • 5 in conversation