Hi,
I'm using proc tabulate to create a table and I'm wondering if there's a way to select one level of a categorical variable to be printed, but keeping the % considering all the levels.
See below the table that I have. I wanted the same table but to export in excel only the lines 'Yes' for the variable sick.
See the code I have right now. Any other ideas are welcome.
Thanks in advance!
ods excel file="C:\ExampleTable1.xlsx" style=minimal;
proc tabulate data=ex;
class sick sex doctor location;
table (sex=' ')*(sick=' ' all), (location=' ' ALL)*(doctor=' ')*(n pctn<sick all>*f=10.1)/ nocellmerge printmiss misstext='0' box="Sick";
keylabel PctN="%" N="n" All="Total";
run;
ods excel close;
For Yes/No True/False type variables I generally find that a numeric value coded 1/0 works best for what you describe as a want. The SUM of a 1/0 coded variable is the count of "Yes" or "True" and the mean is the percentage of Yes.
So perhaps:
data want;
set ex;
sicknum= (Sick='Yes');
run;
proc tabulate data=want;
class sex doctor location;
var Sicknum ;
table (sex=' ')*(sicknum=' ' ,
(location=' ' ALL)*(doctor=' ')*(sum='n'*f=best5. mean='%'*f=percent8.1))/ nocellmerge printmiss misstext='0' box="Sick";
;
run;
Hi Reeza,
thanks for your reply. I'm not very familiar with proc report, would you be able to show me an example on how to use proc report to output a table similar to the one I have now?
For Yes/No True/False type variables I generally find that a numeric value coded 1/0 works best for what you describe as a want. The SUM of a 1/0 coded variable is the count of "Yes" or "True" and the mean is the percentage of Yes.
So perhaps:
data want;
set ex;
sicknum= (Sick='Yes');
run;
proc tabulate data=want;
class sex doctor location;
var Sicknum ;
table (sex=' ')*(sicknum=' ' ,
(location=' ' ALL)*(doctor=' ')*(sum='n'*f=best5. mean='%'*f=percent8.1))/ nocellmerge printmiss misstext='0' box="Sick";
;
run;
Hi, it worked, thank you so much!!
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.