I am wondering if someone can help me create this final table (attached, just refer to the "men" table) using the PROC TABULATE function. I am using the Framingham study data. I've broken age into different age categories called variable "age_category" and number of cigarettes smoked a day into different categories called "cig_category". I am easily able to use the PROC TABULATE function to create a basic table to show the number of a variable for the different catagories:
PROC TABULATE data=biosc.men_frami_baseline;
CLASS cig_category age_category prevhyp;
TABLE prevhyp, cig_category*age_category;
LABEL cig_category="No. of cigarettes smoked per day" age_category="Age
Group" prevhyp="Hypertensive";
run;
This produces a simple table with the number of those who were hypertensive "1" or "0". However, I would like to figure out how to just show the % of total men who were hypertensive="1".
Additionally, I would like to add the following rows to the same table:
The total number of participants per group
The % among the hypertensive who take meds (BPMEDS="1" IF PREVHYP="1")
The % who are diabetic (DIABETES="1")
Also, I would like to include rows for the following also by age_category by smoking_category:
Mean BMI (BMI)
Mean heart rate (HEARTRTE)
Mean cholesterol (TOTCHOL)
I am unsure how to add these specific table elements! Please let me know if I can provide more details. Thank you so much!
That would be the mean, just format it as a percentage.
If you take the mean of a binary variable its the percentage of people with whatever trait = 1.
For the counts/N use the SUM statistic.
@keherder wrote:
I am wondering if someone can help me create this final table (attached, just refer to the "men" table) using the PROC TABULATE function. I am using the Framingham study data. I've broken age into different age categories called variable "age_category" and number of cigarettes smoked a day into different categories called "cig_category". I am easily able to use the PROC TABULATE function to create a basic table to show the number of a variable for the different catagories:
PROC TABULATE data=biosc.men_frami_baseline; CLASS cig_category age_category prevhyp; TABLE prevhyp, cig_category*age_category; LABEL cig_category="No. of cigarettes smoked per day" age_category="Age Group" prevhyp="Hypertensive"; run;
This produces a simple table with the number of those who were hypertensive "1" or "0". However, I would like to figure out how to just show the % of total men who were hypertensive="1".
Additionally, I would like to add the following rows to the same table:
The total number of participants per group
The % among the hypertensive who take meds (BPMEDS="1" IF PREVHYP="1")
The % who are diabetic (DIABETES="1")
Also, I would like to include rows for the following also by age_category by smoking_category:
Mean BMI (BMI)
Mean heart rate (HEARTRTE)
Mean cholesterol (TOTCHOL)
I am unsure how to add these specific table elements! Please let me know if I can provide more details. Thank you so much!
Many users here don't want to download Excel files because of virus potential, others have such things blocked by security software or aren't allowed to due to organization policy.
The total number of participants per group. Would be an N statistic somewhere, but you don't mention what defines a group.
Variables that you want anything other than N or a Percent of N statistic need to go on a VAR statement.
Then request the desired statistic.
The % among the hypertensive who take meds (BPMEDS="1" IF PREVHYP="1") without data this may not be easy with the other things you request. It would be better to create another variable that has a value of 1 when BPMEDS="1" IF PREVHYP="1" and 0 when BPMEDS not equal "1" IF PREVHYP="1"
If all those variables are actually character variables with values of "1" then make them numeric. Otherwise we get into some not really trivial exercises in excluding stuff from the table.
The below assumes that some of your variable Prevhyp and Diabetes are numeric coded 1/0 variables. Something like this may get close to the values. No promises about the way the output looks as I don't open Excel from unknown sources.
PROC TABULATE data=biosc.men_frami_baseline; CLASS cig_category age_category ; var prevhyp bmi totchol HEARTRTE diabetic ; TABLE (prevhyp diabetic )*(sum='N' mean='%'*f=percent8.1) (bmi totchol HEARTRTE) * mean , cig_category*age_category ; LABEL cig_category="No. of cigarettes smoked per day" age_category="Age Group" prevhyp="Hypertensive" ; run;
You want to post code on the forum by opening a text box or code box by clicking on the </> or "running man" icon at the top if the message window. Otherwise the forum will reformat code and may create something that won't actually run.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.