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

Create a work dataset from the TOMHS SAS dataset reading in variables sex, kcalbl, fatbl, probl, chobl, dcholbl, calcbl, sodbl, potbl, and alcbl (use set statement and keep option). The variables after sex are various dietary nutrient intakes calculated from food records collected at baseline. Note: Check attached for the TOMHS SAS dataset dictionary.

 

Run a PROC CONTENTS on the dataset to display descriptions of each variable.

 

Using PROC TABULATE generate the following rtf table. When inserted into Word the display should be nearly identical to what is given below. Note: You will need to modify the labels for each nutrient variable to match those in the first column of the table. You will also need to create and apply a format for sex.

 

Dietary Nutrient Levels at Baseline for TOMHS Men and Women Participants.

Please: see attached for the table. It keeps getting altered when copied here.

 

Thanks.

 

 

 

    
      
       
       
       
       
       
       
       
       
       

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ

Hi:

  Here's a crash course in PROC TABULATE:

1) Every variable used in the TABLE statement must be declared in either a CLASS or VAR statement.

2) A TABULATE table can have 1, 2 or 3 dimensions.

3) A comma (,) is used to separate each of the dimensions in the TABLE statement.

4) The ALL class variable can be used in any dimension to get totals.

5) To nest or cross variables in the dimensions use the * operator.

6) To stack variables in the dimensions use the blank operator.

7) Default statistics are N for class variables and SUM for analysis variables.

😎 There are other keyword statistics you can use in the TABLE statement (like N, SUM, MEAN, MIN, MAX, etc) to request specific statistics.

 

It's good to have an idea of the table you want to generate and how it looks before you write your TABULATE code. Here's an example:

 

 

 proc_tab_example.png

 

In the above table, which uses the SASHELP.HEART data set, the SEX variable is in the column dimension and nested underneath every unique value for this variable are the N and MEAN statistics. Then, the ALL class variable is used to get the overall N and MEAN columns added at the right in the column dimension.

 

The analysis variables, AgeAtStart AgeCHDdiag AgeAtDeath Height Weight Cholesterol, are all listed in the ROW dimension. The table shown in the screen shot is called a two-dimension table. There is only 1 comma in the TABLE statement and therefore, there is no PAGE dimension.

 

Hope this gets you started.

 

cynthia

View solution in original post

5 REPLIES 5
Kurt_Bremser
Super User

You are supposed to solve your homework exercises on your own. That's the whole purpose, isn't it?

Go through your study material and consult the SAS documentation. If your attempt fails and you are puzzled, post your code and log, and example data in a data step, see here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat...

arrytanny
Calcite | Level 5

Tried a few steps....not getting the proc tabulate

 

data diets;

infile 'C:\sas\tomhs.dat' ;

input @030 sex 1.

@180 kcalbl 5.

@186 fatbl 4.1

@191 probl 4.1

@196 chobl 4.1

@201 dcholbl 5.

@207 calcbl 5.

@213 sodbl 5.

@219 potbl 5.

@225 alcbl 4.1;

run;

LIBNAME mylib 'C:\sas';

proc copy IN=work OUT=mylib;

select diets;

run;

LIBNAME mylib 'C:\sas';

data diets;

set mylib.diets;

run;

proc contents data=diets;

run;

proc freq data=diets;

tables sex;

run;

proc means data=diets N MEAN maxdec=1;

var kcalbl fatbl probl chobl dcholbl calcbl sodbl potbl alcbl;

run;

proc tabulate data=diets format=8.0;

class sex;

var kcalbl fatbl probl chobl dcholbl calcbl sodbl potbl alcbl;

tables sex,ALL='Total';

run;

Cynthia_sas
SAS Super FREQ

Hi:

  Here's a crash course in PROC TABULATE:

1) Every variable used in the TABLE statement must be declared in either a CLASS or VAR statement.

2) A TABULATE table can have 1, 2 or 3 dimensions.

3) A comma (,) is used to separate each of the dimensions in the TABLE statement.

4) The ALL class variable can be used in any dimension to get totals.

5) To nest or cross variables in the dimensions use the * operator.

6) To stack variables in the dimensions use the blank operator.

7) Default statistics are N for class variables and SUM for analysis variables.

😎 There are other keyword statistics you can use in the TABLE statement (like N, SUM, MEAN, MIN, MAX, etc) to request specific statistics.

 

It's good to have an idea of the table you want to generate and how it looks before you write your TABULATE code. Here's an example:

 

 

 proc_tab_example.png

 

In the above table, which uses the SASHELP.HEART data set, the SEX variable is in the column dimension and nested underneath every unique value for this variable are the N and MEAN statistics. Then, the ALL class variable is used to get the overall N and MEAN columns added at the right in the column dimension.

 

The analysis variables, AgeAtStart AgeCHDdiag AgeAtDeath Height Weight Cholesterol, are all listed in the ROW dimension. The table shown in the screen shot is called a two-dimension table. There is only 1 comma in the TABLE statement and therefore, there is no PAGE dimension.

 

Hope this gets you started.

 

cynthia

arrytanny
Calcite | Level 5

Thanks Cynthia, this helped.

You are indeed a careful and good teacher...polite personified.

Well done!!! God bless you.

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
  • 5 replies
  • 3229 views
  • 2 likes
  • 3 in conversation