BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Fluorite | Level 6

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

proc report data=sashelp.class nowd headline;

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;

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

1 ACCEPTED SOLUTION

Accepted Solutions
Super User

## Re: How to

How about:

```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

4 REPLIES 4
PROC Star

## 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.

Fluorite | Level 6

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

proc report data=sashelp.class nowd headline;

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;

Super User

## Re: How to

How about:

```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

Fluorite | Level 6

## Re: How to

Thanks SAS Expert. it really help.

Discussion stats
• 4 replies
• 1114 views
• 3 likes
• 3 in conversation