Help using Base SAS procedures

Proc tabulate

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 6
Accepted Solution

Proc tabulate

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.

 

 

 

    
      
       
       
       
       
       
       
       
       
       

 

 


Accepted Solutions
Solution
‎11-18-2017 03:41 PM
SAS Super FREQ
Posts: 9,370

Re: Proc tabulate

Posted in reply to arrytanny

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.

8) 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


All Replies
Super User
Posts: 10,270

Re: Proc tabulate

Posted in reply to arrytanny

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...

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Occasional Contributor
Posts: 6

Re: Proc tabulate

Posted in reply to arrytanny

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;

Super User
Posts: 10,270

Re: Proc tabulate

Posted in reply to arrytanny

The log will be your friend in determining what's wrong.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Solution
‎11-18-2017 03:41 PM
SAS Super FREQ
Posts: 9,370

Re: Proc tabulate

Posted in reply to arrytanny

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.

8) 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

Occasional Contributor
Posts: 6

Re: Proc tabulate

[ Edited ]
Posted in reply to Cynthia_sas

Thanks Cynthia, this helped.

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

Well done!!! God bless you.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 507 views
  • 1 like
  • 3 in conversation