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.
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:
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
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...
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;
The log will be your friend in determining what's wrong.
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:
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
Thanks Cynthia, this helped.
You are indeed a careful and good teacher...polite personified.
Well done!!! God bless you.
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.