Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Home
- /
- Programming
- /
- SAS Procedures
- /
- How to - Get Proc Tabulate's Report Output Being A Data Set By Using P...

Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

🔒 This topic is **solved** and **locked**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 06-30-2016 01:06 PM
(2705 views)

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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:

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

9 REPLIES 9

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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:

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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,

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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;
```

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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,

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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 .

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

Thank you

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

Just sayin'

cynthia

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!

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.