The SAS Output Delivery System and reporting techniques

PROC TABULATE

Accepted Solution Solved
Reply
Super Contributor
Posts: 1,040
Accepted Solution

PROC TABULATE

 

 

I want the output like shown below:What changes do i need to make to the PROC TABULATE code:

 

Proc tabulate data=have;

class source;

var A B C D E;

table (A B C D E ) *source,

sum=

n=

mean=

;

run;

 

 

OUTPUT:

 

 

                       Source1                   Source2

 

               sum N mean              Sum N Mean

A

B

C

D

E

Overall --- --- -----                    ---    ---    -----

 

 

 


Accepted Solutions
Solution
‎05-19-2017 08:41 PM
Grand Advisor
Posts: 10,210

Re: PROC TABULATE


robertrao wrote:

I see. How about using Proc Report instead of tabulate. Can be acheived?

 

Thanks


I think Proc Report would do the calculation if you are willing to have the A B C as columns and the Source as rows.

I don't use Report often and there are a number of headaches with the way cross-column calculations are done I have to be really desparate to go there when I have an easier way.

 

It would take about 7 lines of code to make the A B C category data set similar to the one you provided earlier with the variables (or the variable labels for A B C which would likely be better) as a categorical variable.

View solution in original post


All Replies
Super User
Posts: 1,231

Re: PROC TABULATE

[ Edited ]

Please supply some test data in a format of dataset with datalines (or cards).

 

 

Grand Advisor
Posts: 17,338

Re: PROC TABULATE

Test it until you get what you want. You can't break it...,

 

Try

 

Table (A b c d e all), source*(n mean sum std);

As indicated you should provide either test data or use the relevant SASHELP dataset.

In this case, the SHOES dataset is probably closest to your actual structure. But that's really a guess at this point in time.  

Grand Advisor
Posts: 10,210

Re: PROC TABULATE

If you want "overall" to sum the A B C values tabulate does not work that way.

You would have to do the sum in the data set as a separate value. And the "mean" definition may get a bit tricky especially if you are continuing your previous question about getting counts and percents of your "unwanted" values.

Super Contributor
Posts: 1,040

Re: PROC TABULATE

data temp;

input meas$ source$ surgery;

datalines;

MEAS_A hosp1 1

MEAS_A hosp1 1

MEAS_A hosp1 1

MEAS_A hosp1 1

MEAS_A hosp1 1

MEAS_A hosp1 1

MEAS_A hosp1 1

MEAS_A hosp1 1

MEAS_A hosp2 0

MEAS_A hosp2 1

MEAS_A hosp2 1

MEAS_A hosp2 1

MEAS_A hosp2 1

MEAS_A hosp2 1

MEAS_A hosp2 1

MEAS_A hosp2 1

MEAS_A hosp2 1

MEAS_A hosp2 1

MEAS_A hosp2 1

MEAS_A hosp2 1

MEAS_A hosp2 1

MEAS_A hosp2 1

MEAS_A hosp2 1

MEAS_A hosp2 1

MEAS_A hosp2 1

MEAS_A hosp2 1

MEAS_A hosp2 1

MEAS_B hosp1 1

MEAS_B hosp1 0

MEAS_B hosp1 0

 

 

MEAS_B hosp2 1

MEAS_B hosp2 1

MEAS_B hosp2 0

MEAS_B hosp2 0

MEAS_B hosp2 0

MEAS_B hosp2 0

MEAS_B hosp2 0

MEAS_B hosp2 0

MEAS_B hosp2 0

MEAS_B hosp2 0

MEAS_B hosp2 0

MEAS_B hosp2 0

MEAS_B hosp2 0

MEAS_B hosp2 0

MEAS_B hosp2 0

MEAS_B hosp2 0

MEAS_B hosp2 0

MEAS_B hosp2 0

MEAS_B hosp2 0

MEAS_B hosp2 0

MEAS_B hosp2 0

MEAS_B hosp2 0

MEAS_B hosp2 0

MEAS_B hosp2 0

MEAS_B hosp2 0

MEAS_B hosp2 0

MEAS_B hosp2 0

MEAS_B hosp2 0

;

run;

 

 

 

 

 

I want the output like shown below:What changes do i need to make to the PROC TABULATE code:

 

Proc tabulate data=have;

class source;

var A B ;

table (A B ) *source,

sum=

n=

mean=

;

run;

 

 

OUTPUT:

 

 

                       hosp1                                                  hosp2

 

                   sum N   mean(%)                           Sum N      Mean(%)

MEAS A        8    8     8/8*100=100%                 18   19      18/19*100=94.74%

MEASB         1     3    1/3*100=33.3%                2     28      2/28*100=7.14%     

Overall          9     11   9/11*100= 81.81%        20   47    20/47*100=42.55%

 

Grand Advisor
Posts: 17,338

Re: PROC TABULATE

Why didn't you start with this? And why are there still A B in proc tabulate? And what's actually your Var? The code doesn't line up with your data. 

 

And typing this took the same amount of time as typing an answer would have taken. 

Super Contributor
Posts: 1,040

Re: PROC TABULATE

[ Edited ]

Hello,

 

I am sorry for the confusion. A and B should have been MEAS A and MEAS B respectively.(forgot to change the old code which was suggested by Ballard and Art yesterday).

Shortly after I posted the question I figured out from the article that all the stats have to be in braces to split the results for each of the values under class variable.

http://support.sas.com/resources/papers/proceedings11/173-2011.pdf

 

Lastly, i could not start with this yesterday since I was asked to split the report after I started working on it..

 

Hope you will understand..Also I am working on other tools these days so lost the little knowledge I learnt

 

Thanks

 

 

Grand Advisor
Posts: 10,210

Re: PROC TABULATE

proc tabulate data= temp;
   class meas source;
   var surgery;
   table meas='' all="Overall",
         source='' * surgery='' *( sum n mean="%"*f=percent8.1)
   ;
run;

Note that your original question was showing multiple variable instead of one variable with multiple levels (which is what tabulate works with). the misc ' ' are just to suprees variable names since you didn't provide or indicate a desire for more specific labels other than for mean.

 

Super Contributor
Posts: 1,040

Re: PROC TABULATE

Thanks Ballard...

 

I need it for multiple variables... That example dataset i provided was a mistake. Can your code be expanded to accomodate for multiple variable ?

 

Thanks

Grand Advisor
Posts: 10,210

Re: PROC TABULATE


robertrao wrote:

Thanks Ballard...

 

I need it for multiple variables... That example dataset i provided was a mistake. Can your code be expanded to accomodate for multiple variable ?

 

Thanks


No. Proc tabulate will not sum across other variables.

However you can create a class variable whose values are the names of the other variables and use the example code.

Super Contributor
Posts: 1,040

Re: PROC TABULATE

I see. How about using Proc Report instead of tabulate. Can be acheived?

 

Thanks

Solution
‎05-19-2017 08:41 PM
Grand Advisor
Posts: 10,210

Re: PROC TABULATE


robertrao wrote:

I see. How about using Proc Report instead of tabulate. Can be acheived?

 

Thanks


I think Proc Report would do the calculation if you are willing to have the A B C as columns and the Source as rows.

I don't use Report often and there are a number of headaches with the way cross-column calculations are done I have to be really desparate to go there when I have an easier way.

 

It would take about 7 lines of code to make the A B C category data set similar to the one you provided earlier with the variables (or the variable labels for A B C which would likely be better) as a categorical variable.

Grand Advisor
Posts: 17,338

Re: PROC TABULATE


robertrao wrote:

I see. How about using Proc Report instead of tabulate. Can be acheived?

 

Thanks


Or make your data look like it has one variable by using PROC TRANSPOSE. Then you can use the same idea. 

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 12 replies
  • 237 views
  • 2 likes
  • 4 in conversation