- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
And what is the weight variable?
Please show some sample data, in the form of a working data step.
And the expected result.
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set
Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets
--------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content