BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi

How to generate cross reports through proc report?
From proc report is it possible to generate cross reports.
If yes then can you give me a piece of code for example
1 REPLY 1
Cynthia_sas
Diamond | Level 26
Hi:
Here's a sample that I use in class. The PROC REPORT "ACROSS" usage will produce crosstabs the way you want. So will PROC TABULATE. Compare these 2 outputs:
[pre]

proc report data=sashelp.shoes nowd;
title 'proc report Across';
where region in ('Asia', 'Canada') ;
column product region,(n sales);
define product /group;
define region /across;
define n / 'Count';
define sales /sum;
rbreak after / summarize;
compute after;
product='Total';
endcomp;
run;

proc tabulate data=sashelp.shoes f=7.0;
where region in ('Asia', 'Canada') ;
title 'TABULATE cross-tab';
class product region;
var sales;
table product all,
region * sales=' ' *(n sum*f=comma10.)
all * sales=' '*(n sum*f=comma10.);
keylabel n='Count'
sum='Total Sales'
all='Total';
run;
[/pre]

If you run the 2 procedures and compare the output, you will see that the PROC TABULATE report has a total column to the far right of the report table. This last set of columns comes from the CLASS variable ALL. This is one of the big features and advantages of PROC TABULATE. It is possible, but harder, to get a TOTAL column on the far right of the PROC REPORT output. To achieve it, you would have to use absolute column names in a compute block to get an overall total column.

The documentation for PROC REPORT and the documentation for PROC TABULATE will help you understand how to use each procedure.

cynthia

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 913 views
  • 0 likes
  • 2 in conversation