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


                                        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

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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'

        20 - high='Adult';

    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;

View solution in original post

3 REPLIES 3
Doc_Duke
Rhodochrosite | Level 12

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

Reeza
Super User

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'

        20 - high='Adult';

    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;

Reeza
Super User

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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 1355 views
  • 6 likes
  • 3 in conversation