Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Home
- /
- Programming
- /
- SAS Procedures
- /
- Average and median

Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

🔒 This topic is **solved** and **locked**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 02-08-2019 06:37 PM
(6232 views)

Hi I need to find the code for average and median for the following example. Ans has to by groups and in a new column or row. Thanks in advance. Also I just need mean and median. No std and min and max.

Permno rtrn

0012 0.4

0012 0.5

0012 0.9

0013 0.8

0013 1.5

0013 0.2

0014 1.7

0014 1.8

0014 0.6

I tried proc means but it gives std and min-max which I don't want.

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

@abdulla wrote:

proc means data=pred1 mean median;

by permno;

var abrtrn;

output out=pred2;

run;

I am not getting any median also in my work file. I have to use noprint too. And please make sure I don't want (N, std, Min Max)--- these come with mean in my work file.

The Mean and Median on the Proc statement control output to the results window.

Since you are creating an output set you have to request the statistics for the VAR variables. If no statistic is requested then you get a default set of statistics. Try:

proc means data=pred1 mean median; by permno; var abrtrn; output out=pred2 mean= median= /autoname; run;

The autoname suffixes the variable name with the statistic to differentiate the variables.

You can request different statistics for different variables by providing the variable name with the statistic such as:

mean(var1 var2)= min (var2 var3)=.

There are quite a few options with the output option and you might want to read the documentation.

You may also want to investigate the different output you get using a CLASS statement instead of BY.

11 REPLIES 11

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Tell PROC MEANS not to give you those statistics you don't want, and give you only the statistics you do want.

`proc means data=have mean median;`

--

Paige Miller

Paige Miller

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

I tried this solution by myself but it gives std, min and max value too. I don't want these results. I need only avg and median.

Can you give me an example? I am very new to SAS. So, I need help for that too.

Can you give me an example? I am very new to SAS. So, I need help for that too.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

@abdulla wrote:

I tried this solution by myself but it gives std, min and max value too. I don't want these results. I need only avg and median.

Can you give me an example? I am very new to SAS. So, I need help for that too.

Show your code from the log.

proc means data=sashelp.class mean median; var height weight; run;

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Again I know this solution. I don't want the following which comes with mean

(N, std, Min and Max value)

Now how will I tell the proc means not to give me the above value?

(N, std, Min and Max value)

Now how will I tell the proc means not to give me the above value?

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

by permno;

var abrtrn;

output out=pred2;

run;

I am not getting any median also in my work file. I have to use noprint too. And please make sure I don't want (N, std, Min Max)--- these come with mean in my work file.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

@abdulla wrote:

I tried this solution by myself but it gives std, min and max value too. I don't want these results. I need only avg and median.

Can you give me an example? I am very new to SAS. So, I need help for that too.

Agreeing with @ballardw , I think you are mistaken, however until we see the code you used and the results you are getting, there's no way to resolve this.

--

Paige Miller

Paige Miller

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

by permno;

var abrtrn;

output out=pred2;

run;

I am not getting any median also in my work file. I have to use noprint too. And please make sure I don't want (N, std, Min Max)--- these come with mean in my work file.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

@abdulla wrote:

proc means data=pred1 mean median;

by permno;

var abrtrn;

output out=pred2;

run;

I am not getting any median also in my work file. I have to use noprint too. And please make sure I don't want (N, std, Min Max)--- these come with mean in my work file.

The Mean and Median on the Proc statement control output to the results window.

Since you are creating an output set you have to request the statistics for the VAR variables. If no statistic is requested then you get a default set of statistics. Try:

proc means data=pred1 mean median; by permno; var abrtrn; output out=pred2 mean= median= /autoname; run;

The autoname suffixes the variable name with the statistic to differentiate the variables.

You can request different statistics for different variables by providing the variable name with the statistic such as:

mean(var1 var2)= min (var2 var3)=.

There are quite a few options with the output option and you might want to read the documentation.

You may also want to investigate the different output you get using a CLASS statement instead of BY.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

The code worked nicely. Thanks a lot.

What will be code if I want to use data statement instead of proc? Also, I have some missing values in my abrtrn column. How will I exclude these missing values?

If I use the above proc statement, where will I write "noprint"?

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

@abdulla wrote:

What will be code if I want to use data statement instead of proc?

Don't do this in a data step. It's very simple in PROC MEANS.

Also, I have some missing values in my abrtrn column. How will I exclude these missing values?

PROC MEANS handles missing values properly. No need to exclude them.

If I use the above proc statement, where will I write "noprint"?

Some things are easily found by looking in the documentation for PROC MEANS.

--

Paige Miller

Paige Miller

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Thanks Paige Miller

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

**If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. **

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.