BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
turcay
Lapis Lazuli | Level 10

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ

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

9 REPLIES 9
Astounding
PROC Star

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

turcay
Lapis Lazuli | Level 10

Hello @Astounding,

 

Thank you for trying to help me 🙂 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

Cynthia_sas
SAS Super FREQ

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

turcay
Lapis Lazuli | Level 10

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,

Ksharp
Super User

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

turcay
Lapis Lazuli | Level 10

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,

Ksharp
Super User

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 .

turcay
Lapis Lazuli | Level 10

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

 

Thank you

Cynthia_sas
SAS Super FREQ
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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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
  • 9 replies
  • 2008 views
  • 2 likes
  • 4 in conversation