Hi everyone,
I'm having a hard time editing the following code to generate weighted N and column percentage using proc tabulate. My dataset is survey design but only has weights and no strata nor cluster. My expected result is to have weighted frequency of lab test outcome by condition and race group.
Using survey frequency is less flexible compared to tabulate in term of table format.
Any help on rewriting the code is greatly appreciated!
proc tabulate data=test(where=(cohort=1)) noseps ;
class flag_A1C9_lst Cat_raceeth obesity Hyperlipidemia Hypertension ;
table flag_A1C9_lst,(all obesity*Cat_raceeth
Hyperlipidemia*Cat_raceeth
Hypertension*Cat_raceeth)*(n*f=comma8. colPctN*f=4.1);
run;
What do you get when you add a Weight statement to your proc tabulate:
proc tabulate data=test(where=(cohort=1)) noseps ;
class flag_A1C9_lst Cat_raceeth obesity Hyperlipidemia Hypertension ;
weight FWGT_2019;
table flag_A1C9_lst,(all obesity*Cat_raceeth
Hyperlipidemia*Cat_raceeth
Hypertension*Cat_raceeth)*(n*f=comma8. colPctN*f=4.1);
run;
If your variable FWGT_2019 is actually a count variable, such as from summarizing data, you may actually want a FREQ statement instead of weight.
And what is the weight variable?
Please show some sample data, in the form of a working data step.
And the expected result.
data sample;
input uniqueid $ flag_A1C9_lst Cat_raceeth obesity Hyperlipidemia Hypertension cohort FWGT_2019
;
datalines;
1 1 1 1 1 0 1 1473
2 0 2 0 1 1 0 2296
3 . 3 1 0 1 1 7484
;
run;
The expected output looks like below:
Thank you for your help!
What do you get when you add a Weight statement to your proc tabulate:
proc tabulate data=test(where=(cohort=1)) noseps ;
class flag_A1C9_lst Cat_raceeth obesity Hyperlipidemia Hypertension ;
weight FWGT_2019;
table flag_A1C9_lst,(all obesity*Cat_raceeth
Hyperlipidemia*Cat_raceeth
Hypertension*Cat_raceeth)*(n*f=comma8. colPctN*f=4.1);
run;
If your variable FWGT_2019 is actually a count variable, such as from summarizing data, you may actually want a FREQ statement instead of weight.
FREQ seems to work?
data sample;
input uniqueid $ flag_A1C9_lst Cat_raceeth obesity Hyperlipidemia Hypertension cohort FWGT_2019
;
datalines;
1 1 1 1 1 0 1 1473
2 0 2 0 1 1 0 2296
3 . 3 1 0 1 1 7484
;
run;
proc tabulate data=sample(where=(cohort=1)) noseps ;
class flag_A1C9_lst Cat_raceeth obesity Hyperlipidemia Hypertension / missing ;
freq FWGT_2019;
table flag_A1C9_lst,(all obesity*Cat_raceeth
Hyperlipidemia*Cat_raceeth
Hypertension*Cat_raceeth)*(n*f=comma8. colPctN*f=4.1);
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!
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.