# SAS Proc Means

### SAS Day 27: Proc Means

We use Statistical summary to demonstrate the mean, median, max, min, Q1, Q3..
In SAS we can either use Proc Means or Proc Univariate to achieve the goals.
Today we will introduce how to generate statistical summary using Proc Means.

#### Basic Syntax:

```proc means data= dummy noprint;
var age; /*Any continuous variable: age, weight, height*/
where &cond; /*Subset the population, ex: Safety population="Y"*/
output out=temp1 n=n mean=mean std=std min=min median=median max=max q1=q1 q3=q3;
/*Any statistical meausures we need to present*/
run;```

The above step will generate the basic summary, we can manipulate with the format a little bit so we can present the data in a nice way.

95839 / Pixabay

#### Basic Syntax:

```data test;
length col \$100.;
set temp1;
ord=0.5; label="Summary Statistics of Age"; output;
ord=1; label=' N'; col=strip(put(n,best8.)); output;
ord=2; label=' Mean'; col=strip(put(mean,8.1)); output;
ord=3; label=' STDEV'; col=strip(put(std,8.2)); output;
ord=4; label=' Median'; col=strip(put(median,8.1)); output;
*ord=4.5; hd=' Q1, Q3'; col1=strip(put(q1,8.1))||', '||strip(put(q3,8.1)); output;
ord=5; label=' Min, Max'; col=strip(put(min,8.1))||', '||strip(put(max,8.1)); output;
keep  ord label col;
run;```

Note: we can tailor the decimal points “8.1” or “8.2” based on the output requirement.

Now, finally, we can demonstrate our data to the audience.

Bonus Macro Coding:

Most of the time we need to develop Statistical summary for many continuous variables, such as Age, Height, Weight, Disease Lines or and so on. Therefore, it would be extremely useful if we modify the previous code a little to create a Macro Proc Means.

Basic Syntax:

```%macro mean(var=, out=,  cond=);
proc means data=test noprint;
var &var;
where &cond;

output out=temp n=n mean=mean std=std min=min median=median max=max q1=q1 q3=q3;
run;

data &out;
set temp;
ord=0.5; label="Summary Statistics of Age"; output;
ord=1; label=' N'; col=strip(put(n,best8.)); output;
ord=2; label=' Mean'; col=strip(put(mean,8.1)); output;
ord=3; label=' STDEV'; col=strip(put(std,8.2)); output;
ord=4; label=' Median'; col=strip(put(median,8.1)); output;
*ord=4.5; hd='  Q1, Q3'; col1=strip(put(q1,best8.)))||', '||strip(put(q3,best8.))); output;
ord=5; label=' Min, Max'; col=strip(put(min,8.1))||', '||strip(put(max,8.1)); output;
keep  ord label col;
run;
%mend;```

Now we can just use the macro to call all the desired variables.

%mean (var=height, out=age, cond= safety=”y”)