BookmarkSubscribeRSS Feed
ChristinaWang
Calcite | Level 5


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

1 REPLY 1
ballardw
Super User

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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 619 views
  • 0 likes
  • 2 in conversation