BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
MilenaNF
Fluorite | Level 6

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.

 

Example Table 1.png

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;

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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;
  

View solution in original post

5 REPLIES 5
Reeza
Super User
Not easily. It’s easier to push the proc tabulate table to a dataset, filter it and then use proc report to display it.
MilenaNF
Fluorite | Level 6

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?

Reeza
Super User
Sorry, I'm not as familiar with PROC REPORT either.

I would expect that you would use an ACROSS to specify the doctors/location and then the Gender/Sick Variable as grouping variables.
You can use COMPUTE if want to custom format your data.

Note that you I strongly suspect you'll still need to use PROC TABULATE to get the percentages or PROC FREQ.

You could also just use PROC FREQ + TRANSPOSE + PROC PRINT to display it if you're not familiar with PROC REPORT.

PROC TABULATE has an OUT= option on the statement that will push your data to an output data set.

Proc Report examples - there's a few that are relevant to you or you can find many many examples on Lexjansen.com. I'd probably find the one that was closest to what I wanted and start from there.
https://documentation.sas.com/?docsetId=proc&docsetVersion=9.4&docsetTarget=n1pl56sdqo09cyn1fifuhcz8...
ballardw
Super User

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;
  
MilenaNF
Fluorite | Level 6

Hi, it worked, thank you so much!!

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 2764 views
  • 4 likes
  • 3 in conversation