Hello,
I am trying to create an easy-to-read output table with 42 variables (rows) and their distribution within gender classes.
I could use proc freq as follow:
proc freq data=mydata; table (anm_diabete anm_scompenso_cardiaco anm_pacemaker anm_bpco ... )*ang_sex/ norow nopercent; run;
but I would like to unify the results in a single table.
I tryed to use proc tabulate with this code:
proc tabulate data=mydata;
class anm_diabete anm_scompenso_cardiaco anm_pacemaker anm_bpco ... ang_sex;
table (anm_diabete anm_scompenso_cardiaco anm_pacemaker anm_bpco ...),
ang_sex*(n='N'*f=8.0 pctn<anm_diabete anm_scompenso_cardiaco anm_pacemaker anm_bpco ...>='%'*f=8.1) / box=' ';
run;
This procedure works with few variables, but with the entire set of variables (42 variables), frequencies are totally different.
Here is the output with only 4 variables (and correct frequencies/percentages):
Here is the output with all 42 variables inserted in the proc tabulate (only first 8 variables shown):
Any ideas about how to correctly use proc tabulate or any macro to unified results from proc freq?
Thanks in advance!
The following Sample shows how to reshape the output data set from multiple TABLES requests in PROC FREQ when using ODS OUTPUT:
Missing values of CLASS variables.
Add /missing to the CLASS statement to get a count of the missing values as Proc Freq does by default. BUT Tabulate will then treat the Missing as a class for percentages. Depending on what you want for display any of the report procedures such as Tabulate or Report may require more work than a simple call to the procedure.
Note, for future reference it is a good idea to place the output of both procedures when discussing differences in output for the code shown. The output you show for Proc Freq will not be generated by the code shown. It would show a separate table for each pair of variables with the percentage on a different row in the cell, a row and column total, and likely for some of the variables a frequency for missing. IF you are sending the output to ODS OUTPUT and manipulating the the output data set created to display the results then show that code, not simple Proc Freq.
Thank you for suggestions. Unfortunately I do no want percentages calculated on missing values. I am trying to find a solution to display in a sigle table (as proc tabulate), all results from proc freq. Without "missing" statement.
I woul like a table like this:
Labels are in examples.
I suppose I have to manipulate ods output from proc freq with a macro to obtain results as above
@Elena173 wrote:
Thank you for suggestions. Unfortunately I do no want percentages calculated on missing values.
Perhaps there is a misunderstanding, but if you don't want the missings included, PROC TABULATE will do that (as long as you do NOT use the MISSING option).
The following Sample shows how to reshape the output data set from multiple TABLES requests in PROC FREQ when using ODS OUTPUT:
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.
Ready to level-up your skills? Choose your own adventure.