BookmarkSubscribeRSS Feed

PROC REPORT Next Steps

Started ‎06-11-2018 by
Modified ‎06-04-2019 by
Views 8,106

Did you miss the Ask the Expert session on Next Steps with PROC REPORT? Not to worry, you can watch it on-demand whenever you want.  The slides and demo code are attached as well.

 

Watch the webinar

 

The session covers using aliases and temporary variables in PROC REPORT.  It

  • Defines aliases.
  • Defines temporary variables.
  • Examples demonstrate how to use aliases to show multiple statistics, change summary values, and apply multiple formats to the same raw value.
  • Examples demonstrate how to use temporary variables to fill in group and order values, apply IF/THEN logic based on group values, and how to calculate percentages within nested groups.

 

PROC Report Next Steps image.jpg 

 

Here are some highlighted questions from the Q&A segment held at the end of the session for ease of reference.

 

I have an across variable and tried to create a percent column under each value but I got all missing values.  Why?

With an across variable you must refer to columns in the form _cn_.  I suspect you got all missing because you had the computed variable name in the compute block but you need to use _cn_ to reference those columns.    

Refer to this sample to see how to calculate variables under an across.

Sample 43091: Calculate percentages under an ACROSS variable using PROC REPORT

 

When I am debugging my code, is there a way to see the values of the temporary variables?

Yes, you can output the temporary variables in a LINE statement.  The syntax is

      compute before region; 

            denomreg = sales.sum;

            line denomreg 8.;

      endcomp;

While debugging your code you can also add a dummy computed column to the end of your COLUMN statement.  Then assign the computed column to the temporary variable.

 

In the example that showed the overall sum and mean, is there a way to use a different format for one of those rows?

Yes, you can apply a different format to a summary row by adding a CALL DEFINE statement to the compute block that controls the summary row you want to change.  If you want to change the row generated by the RBREAK statement then the CALL DEFINE statement should be added to the compute after block.

 

How do I sort the table by the overall sum or one of the statistics that I am not showing in the table?

A PROC REPORT cannot be sorted by an analysis variable.  You need to summarize the data in one step and create a data set with the results. With PROC REPORT, create the final report that would allow you to define the summarized value as group or order variable. 

 

When I use PROC TABULATE, I use ALL to create totals and grand totals.  PROC REPORT does not respect that, why not?

Every procedure is different.  PROC TABULATE as the keyword ALL.  PROC REPORT does not have that keyword.  You can get the totals and grand totals with PROC REPORT.  Using an analysis variable multiple times will let you get row totals, that is like using ALL in the column dimension in TABULATE.  The RBREAK statement will create a summary row containing the column totals. 

 

I know I can test _BREAK_ because it is an automatic variable.  Can I use it in a COLUMN statement?

To use in the COLUMN statement it would need to be in your input data set or creating one (like you would a compute variable).  However, I don’t recommend creating a variable called _break_.  You could create a computed column and set the value of the computed column to _break_ so you can see what the value is on a given row.

This paper is a very good reference for learning about breaking in PROC REPORT.

Go Ahead and _BREAK_-down: Advanced COMPUTE Block Examples

 

How is the length of a temporary character variable set?

All the defaults are used. But PROC REPORT generally assumes that temporary variables are numeric. The best way to assure that you get the right type and length is to use a LENGTH statement in your COMPUTE block.­

 

Are you required to define all Column statement variables?

No, you're not required to DEFINE each variable. But if you do NOT use a DEFINE statement, then you take all the defaults for usage, format, label, etc. If you're OK with that, then don't use a DEFINE.­

 

What is the difference in creating alias in Proc Report vs creating variables in pre-processing data step?
In general, it is user preference to pre-process the data and create a copy of a variable versus using an alias in PROC REPORT. Some programmers do not want to add more variables to the data set so that like that they can create a copy inside of the procedure.

 

In your Proc Format to highlight the background of a cell, what would be the color if the value is 50000? Shouldn't the other range be 50001-1000000 so it does not overlap with the 1-50000?
The cell would be blue if the value was exactly 50,000. You are correct, the values in the PROC FORMAT step should not have overlapped.

 

Do temporary variables have to be numeric?
No, temporary variables can be either numeric or character.

 

Could you do this with a "Display" instead of "Group" when defining region? If so what is the benefit of one versus the other?

Group combines like variable values and will sum (or whatever statistic you are using) any analysis variables that are specified. Display is just that - it is like PROC PRINT and does not grouping or summation.

 

Want more tips? Be sure to subscribe to the Ask the Expert board to receive follow up Q/A, slides and recordings from other SAS Ask the Expert webinars.

 

Comments
ZS2

Is it possible to give two different titles while splitting the data into two pages using ID variables in proc report?

Hi @ZS2 ,
A TITLE statement is attached to the procedure output. That means that it cannot be changed during the middle of the report, unless of course, you are using #byval.
You can use a LINE statement in a compute before _page_ block to mimic a title. The text is between the text from a TITLE statement and the headers of the procedure. You will need to create a dummy variable upon which a page break is forced in PROC REPORT. Here is an example:
/* Demonstrate the circumvention */
data price;
set sashelp.pricedata(obs=50);
if _n_<=25 then pageit=1;
else if 50 >= _n_ > 25 then pageit=2;
else if 75 >= _n_ > 50 then pageit=3;
else pageit=4;
run;

ods pdf file='c:\temp\test2.pdf';

title 'created by title statement';
proc report data=price nowd;
column pageit date price1-price12;
define date / order id;
define price7 / page;
define pageit / order noprint;
break after pageit / page;

compute before _page_;
length text $100;
if pageit=1 then text='this is the first page';
else if pageit=2 then text='this is the second page';
else if pageit=3 then text='this is the third page';

line text $100.;
endcomp;
run;
ods pdf close;
Jane

@wreeves 

 

With the obs=50 dataset option in the SET Statement, you will never see pages 3 or 4.

I used obs=50 to keep the output to minimum and yet be able to see the results of using ID, PAGE, and LINE. That isn't something I would do in a production report.
Version history
Last update:
‎06-04-2019 11:29 AM
Updated by:
Contributors

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Article Labels
Article Tags