Help using Base SAS procedures

How to - Get Proc Tabulate's Report Output Being A Data Set By Using Proc Means

Accepted Solution Solved
Reply
Super Contributor
Posts: 381
Accepted Solution

How to - Get Proc Tabulate's Report Output Being A Data Set By Using Proc Means

Hello everyone,

 

I would like to get PROC TABULATE's report output as a data set. But as we know, it is not possible to get the data set by using OUT= option in PROC TABULATE. So that, I decided to use PROC MEANS procedure and get the same structure with PROC TABULATE's report output. I almost got the same output except the "Target"(0&1) values. How can I get these values in my desired data set.

 

Can somebody help me, please?

 

Data Have;
Length Predicted 8 Target 8 Bucket 8;
Infile Datalines Missover;
Input Predicted Target Bucket;
Datalines;
0.7 0 1
0.6 0 2
0.8 1 3
0.7 0 2
0.6 0 3
0.8 1 1
0.7 0 3
0.6 0 1
0.8 1 2
0.7 0 1
0.6 0 2
0.8 1 3
0.7 0 2
0.6 0 1
0.8 1 3
;
Run;
Ods Listing Close;
ODS OUTPUT Summary=Want(Rename=(MEAN=_MEAN MIN=_MIN MAX=_MAX MEDIAN=_MEDIAN N=_N));
PROC MEANS Data=Have MEAN MIN MAX MEDIAN N STACKODSOUTPUT;
VAR Predicted;
CLASS Bucket;
Run;
 
Ods Output Close; 
Ods Listing; 
PROC TABULATE DATA=Have FORMAT=BEST12.8 Out=Have;
     VAR Predicted;
     CLASS Target /  ORDER=UNFORMATTED MISSING;
     CLASS Bucket /  ORDER=UNFORMATTED MISSING;
     TABLE /* Row Dimension */
Bucket,
/* Column Dimension */
Predicted*(Mean Min Max Median) Target*N N;
RUN;

Thank you

 


Accepted Solutions
Solution
‎07-01-2016 10:01 AM
SAS Super FREQ
Posts: 8,743

Re: How to - Get Proc Tabulate's Report Output Being A Data Set By Using Proc Means

Hi:

  I do NOT believe that you will every get Target 0/1 numbers as you want, from PROC MEANS, in the same way that you can do with PROC TABULATE. However, (and I am not just saying this because I really like PROC REPORT), PROC REPORT can give you EXACTLY what you want in a report format and a DATASET format, as shown in the attached output:

 

comparison_of_outputs.png

 

So rather than spin your wheels trying to make PROC MEANS do something that PROC TABULATE or PROC REPORT could do better, why not just use PROC TABULATE if all you need is report output or use PROC REPORT if you need a report and/or a dataset.

 

cynthia

View solution in original post


All Replies
Super User
Posts: 5,092

Re: How to - Get Proc Tabulate's Report Output Being A Data Set By Using Proc Means

Actually PROC TABULATE does support OUT= on the PROC statement.  Maybe that will make things easier.

Super Contributor
Posts: 381

Re: How to - Get Proc Tabulate's Report Output Being A Data Set By Using Proc Means

Hello @Astounding,

 

Thank you for trying to help me Smiley Happy But I know the PROC TABULATE supports OUT= option but I want to see the following data set. How can I get this? PROC TABULATE OUT= optipn does not brings this data set.

 

Desired.png

Solution
‎07-01-2016 10:01 AM
SAS Super FREQ
Posts: 8,743

Re: How to - Get Proc Tabulate's Report Output Being A Data Set By Using Proc Means

Hi:

  I do NOT believe that you will every get Target 0/1 numbers as you want, from PROC MEANS, in the same way that you can do with PROC TABULATE. However, (and I am not just saying this because I really like PROC REPORT), PROC REPORT can give you EXACTLY what you want in a report format and a DATASET format, as shown in the attached output:

 

comparison_of_outputs.png

 

So rather than spin your wheels trying to make PROC MEANS do something that PROC TABULATE or PROC REPORT could do better, why not just use PROC TABULATE if all you need is report output or use PROC REPORT if you need a report and/or a dataset.

 

cynthia

Super Contributor
Posts: 381

Re: How to - Get Proc Tabulate's Report Output Being A Data Set By Using Proc Means

Thank you very much @Cynthia_sas,

 

Yes, you are right but after I got the output I will do some additional calculations so that is the reason why I select the PROC SQL because doing some calculations over the PROC SQL is easier than the PROC REPORT calculation. But in terms of performance, I do not have much knowledge. Maybe PROC REPORT is better than PROC SQL with regard to performance.

 

Thank you,

Super User
Posts: 9,687

Re: How to - Get Proc Tabulate's Report Output Being A Data Set By Using Proc Means

Use SQL instead.

 

Data Have;
Length Predicted 8 Target 8 Bucket 8;
Infile Datalines Missover;
Input Predicted Target Bucket;
Datalines;
0.7 0 1
0.6 0 2
0.8 1 3
0.7 0 2
0.6 0 3
0.8 1 1
0.7 0 3
0.6 0 1
0.8 1 2
0.7 0 1
0.6 0 2
0.8 1 3
0.7 0 2
0.6 0 1
0.8 1 3
;
Run;
proc sql;
select Bucket,
       mean(Predicted) as mean,
       min(Predicted) as min,
       max(Predicted) as max,
       median(Predicted) as median,
       sum(Target=0) as Target_0,
       sum(Target=1) as Target_1,
       (select count(*) from have) as n
 from have
   group by Bucket;
quit;

 

x.png

Super Contributor
Posts: 381

Re: How to - Get Proc Tabulate's Report Output Being A Data Set By Using Proc Means

Hello,

 

@Ksharp Thank you fro trying to help me.

 

But in EG 5.1, Median function gives the following error. And this warning lead to prevent grouping calculation. Do you have an idea how to avoid this situation?

 

 

WARNING: The MEDIAN function has been called with only one argument.  However, it is not an SQL aggregate function, and this call

         will not cause SQL aggregation.

 

Thank you,

Super User
Posts: 9,687

Re: How to - Get Proc Tabulate's Report Output Being A Data Set By Using Proc Means

What version of SAS are you using ? if it is not SAS9.4 , you can't use MEDIAN() in SQL.

The workaround way is computing MEDIAN in PROC MEANS ,then merged it back to the SQL's dataset .

Super Contributor
Posts: 381

Re: How to - Get Proc Tabulate's Report Output Being A Data Set By Using Proc Means

Yes, It is not 9.4 It is 9.4 okay I will merge PROC MEANS Median with PROC SQL output.

 

Thank you

SAS Super FREQ
Posts: 8,743

Re: How to - Get Proc Tabulate's Report Output Being A Data Set By Using Proc Means

Or, you could use PROC REPORT, which does give you the MEDIAN function and would not require more than 1 pass through the data.

Just sayin'

cynthia
☑ This topic is solved.

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

Discussion stats
  • 9 replies
  • 421 views
  • 2 likes
  • 4 in conversation