I'm analyzing weighted survey data using PROC SURVEYFREQ. Column percentages are automatically calculated using a denominator that includes the weighted frequency of BOTH domain / flag_1 = 1 and domain / flag_1 = 0 (i.e., 53649500) (See pic). So the column percentage is 2.7866% (i.e., 1494991 / 53649500 = 2.7866%).
How can I confine the calculation of column percentages to a given domain, so that the denominator is the weighted frequency of domain = 1 (i.e., 2071466)?
My desired column percentage calculation would be:
1494991 / 2071466 = 72.171%
Here's my syntax:
proc surveyfreq data=&dataset nomcar;
stratum sdmvstra;
cluster sdmvpsu;
weight &weight;
/* DOMAIN: used instead of the WHERE or BY statement to provide analyses of subgroups. */
/* The DOMAIN statement is not available with the SURVEYFREQ procedure. */
/* Use the DOMAIN variable in the TABLES statement instead */
TABLE
/* NHANES variables */
flag_1*
(
ever_used
cann_use_status
cann_use_status2
monthly_yr
/* time_since_monthly_use */
/* time_since_monthly_use_unit */
times_month
joints_pipes_day
/* last_used */
/* last_use_unit */
/* Calculated variables */
/* mos_since_last_use */
/* yrs_since_last_use */
/* mos_since_monthly_use */
/* yrs_since_monthly_use */
)
/ cl col chisq cellchi2 relrisk;
/* *year/ cl col chisq cellchi2 relrisk; */
FORMAT
/* NHANES variables */
ever_told_mi yes_no_fmt.
ever_used ever_usedfmt.
cann_use_status cann_use_statusfmt.
cann_use_status2 cann_use_status2fmt.
monthly_yr monthly_yrfmt.
times_month times_monthfmt.
joints_pipes_day joints_pipes_dayfmt.
year yearfmt.
/* Calculated variables */
/* mos_since_last_use */
/* yrs_since_last_use */
/* mos_since_monthly_use mos_since_monthly_usefmt. */
/* yrs_since_monthly_use */
;
run;
Have you tried including the ROW percentages in the output?
Have you tried including the ROW percentages in the output?
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.