Solved
Contributor
Posts: 21

# How to

Hi Expert,

I'm new with SAS programming. I'd sample code as follow and it works. It calculate the mean for height base on age.

My question now is, from the table "Class" in SASHelp, there is also for weight. How can i include the height and weight to be shown on the report?

Hope any expert in sas programming can help.

Sample code:-

=====================================

data class;

set sashelp.class;

h2=height*2;

run;

proc tabulate data=class format=8.1;

class sex age;

var height h2;

table age, sex*(height*mean) (height h2)*mean;

run;

col age sex,height height h2;

define age / group;

define sex / across;

define height  / mean format=8.1;

define h2 / computed format=8.1;

compute h2;

h2= _c4_ * 2;

endcomp;

run;

===========================

Accepted Solutions
Solution
‎08-30-2012 12:42 AM
Super User
Posts: 10,787

## Re: How to

```proc report data=sashelp.class nowd headline;
col age sex,(height weight) height height=h2 weight weight=w2;
define age / group;
define sex / across;
define height  / mean format=8.1;
define weight  / mean format=8.1;
define h2 / mean format=8.1 'h2';
define w2 / mean format=8.1 'w2';
compute h2;
h2=h2 * 2;
endcomp;
compute w2;
w2=w2 * 2;
endcomp;
run;

```

Ksharp

All Replies
Super User
Posts: 6,785

## Re: How to

Regarding PROC TABULATE only, you have to take two steps to include WEIGHT.  First, add WEIGHT to the VAR statement:

var height h2 weight;

Second, place WEIGHT in the TABLE statement in the spot(s) where you would like it to appear on your table.  One possibility:

table age, sex*(height weight) * mean (height h2)*mean;

Experiment a bit to get a feel for it.

Contributor
Posts: 21

## Re: How to

Hi Astouding,

Thanks for the advise. I'd change the code and follow your suggestion. but my proc report seem to be unable to display correctly.

data class;

set sashelp.class;

h2=height*2;

w2=weight*2;

run;

proc tabulate data=class format=8.1;

class sex age;

var height h2 weight w2;

table age, sex*(height weight*mean) (height h2 weight w2)*mean;

run;

col age sex, height weight height h2 weight w2;

define age / group;

define sex / across;

define height  / mean format=8.1;

define weight  / mean format=8.1;

define h2 / computed format=8.1;

define w2 / computed format=8.1;

compute h2;

h2= _c4_ * 2;

endcomp;

compute w2;

w2= _c4_ * 2;

endcomp;

run;

Solution
‎08-30-2012 12:42 AM
Super User
Posts: 10,787

## Re: How to

```proc report data=sashelp.class nowd headline;
col age sex,(height weight) height height=h2 weight weight=w2;
define age / group;
define sex / across;
define height  / mean format=8.1;
define weight  / mean format=8.1;
define h2 / mean format=8.1 'h2';
define w2 / mean format=8.1 'w2';
compute h2;
h2=h2 * 2;
endcomp;
compute w2;
w2=w2 * 2;
endcomp;
run;

```

Ksharp

Contributor
Posts: 21

## Re: How to

Thanks SAS Expert. it really help.

🔒 This topic is solved and locked.