## Help with Proc freq-sas9.2

Solved
Super Contributor
Posts: 1,041

# Help with Proc freq-sas9.2

Age                                                              Gender               Ethnicity ..............................................

<=40      41-60     61-74      >=75                 F          M

n  %       n  %        n  %        n  %               n  %      n  %

Partial

Complete

Total

All the variables are in a single dataset.

partial and complete are two values under a single variable in the same dataset

I Have the formats written for age and gender

Could anyone help me to build the code..please

Also i have similar other tables with columns to be added horizontally and they are present in the same dataset too

Accepted Solutions
Solution
‎09-13-2012 11:24 AM
Super User
Posts: 20,731

## Re: Help with Proc freq-sas9.2

Are you looking for a statistical test or how to derive the table?  And how does your data look?

PROC FREQ won't produce a table like you've shown and I'd recommend the other way anyways, ie partial/complete across the top and the variables down the side.

proc format;

value age_fmt

low - 13 = 'Pre-Teen'

13 - 19 = 'Teen'

value bmi_fmt

low - 18.5 = 'Underweight'

18.5 - 25 = 'Normal'

25 - 30 = 'Overweight'

30 - high = 'Obese';

run;

data class;

set sashelp.class;

bmi=(weight/height**2) * 703;

run;

proc tabulate data=class;

class age sex bmi;

table bmi, age*(n rowpctn='%') sex(n rowpctn='%');

format age age_fmt. bmi bmi_fmt.;

run;

All Replies
Posts: 2,116

## Re: Help with Proc freq-sas9.2

Karun,

I suspect that your question is not how to get the data for the tables, but rather how to display it ranging across rather than in different tables.

To address the display, you need to use PROC TABULATE rather than FREQ.  There are examples in the documentation on how to put multiple variables across the top.

Doc Muhlbaier

Duke

Solution
‎09-13-2012 11:24 AM
Super User
Posts: 20,731

## Re: Help with Proc freq-sas9.2

Are you looking for a statistical test or how to derive the table?  And how does your data look?

PROC FREQ won't produce a table like you've shown and I'd recommend the other way anyways, ie partial/complete across the top and the variables down the side.

proc format;

value age_fmt

low - 13 = 'Pre-Teen'

13 - 19 = 'Teen'

value bmi_fmt

low - 18.5 = 'Underweight'

18.5 - 25 = 'Normal'

25 - 30 = 'Overweight'

30 - high = 'Obese';

run;

data class;

set sashelp.class;

bmi=(weight/height**2) * 703;

run;

proc tabulate data=class;

class age sex bmi;

table bmi, age*(n rowpctn='%') sex(n rowpctn='%');

format age age_fmt. bmi bmi_fmt.;

run;

Super User
Posts: 20,731

## Re: Help with Proc freq-sas9.2

Add all in where you need it. As an analyst you're allowed to suggest people do things differently in requests...its what defines a good analyst from a bad actually, IMO.

proc tabulate data=class;

class age sex bmi;

table bmi all, (age all)*(n rowpctn='%') (sex all)*(n rowpctn='%');

format age age_fmt. bmi bmi_fmt.;

run;

🔒 This topic is solved and locked.