Help using Base SAS procedures

table inside table

Reply
New Contributor
Posts: 2

table inside table


Hi all,

I have a table need to creat that looks like the following.

YesNo
age(45,50)
age(50,55)
age(55,60)
age (60,65)
age(65,70)

age is a continous variable, I can do if statement to separate by agecat (45,50),(50,55),(55,60),(60,65),(65,70).

yes and no  are two levels from v3.

but each cell need another 2*2 table in side for v1 and v2.

I've attached the part of the data.

Thanks,

Christina

Attachment
Super User
Posts: 11,343

Re: table inside table

Posted in reply to ChristinaWang

PROCs FORMAT and Tabulate

First, instead of creating lots of if/then/else code use a format to create groups and text labels.

with your labels one can't tell which end to include in the ranges below. You need to decide that before proceding.

Proc Format library=work;

value age

45 - 49 = '45 to 49'

50 - 54 = '50 to 54'

55 - 59 = '55 to 59'

60 - 64 = '60 to 64'

65 - 70 = '65 to 70'

;

/* assumes you have variable coded 1 is yes 0 is no , if the other way around change the text*/

value yn

1 = 'Yes'

0 = 'No'

;

run;

/* this should make a table similar to what you show. IF ANY OF THE V1 V2 OR V3 ARE MISSING

you may want the option /missing in class statement.

*/

proc tabulate data=<your data set name here> ;

     class age;

     class v1 v3 ; /* I didn't put V2 in here cause I don't know what your coding looks like */

    format age age. v1 v3 yn. ;

     table age',

              v3' *n=''*f=f6.0;

run;

Making actual 2x2 tables within the cells of age and V3 might be more work than it's worth. but you can get similar information with

proc tabulate data=<your data set name here> ;

     class age;

     class v1 v2 v3 ; /* I didn't put V2 in here cause I don't know what your coding looks like */

    format age age. v1 v3 yn. ;

     table age' * V2,

              v3' * V1 * n=''*f=f6.0;

run;

LABELS for v1 v2 and v3 will make the table more useful.

Something like:

label V1 = 'Response to question 1';

Ask a Question
Discussion stats
  • 1 reply
  • 147 views
  • 0 likes
  • 2 in conversation