Hi all,
I have a table need to creat that looks like the following.
Yes | No | |
---|---|---|
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
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';
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.