/*****************************************************************/ /* This file contains the examples from SAS Technical Report */ /* P-258, Using the REPORT Procedure in a Nonwindowing */ /* environment. */ /* */ /* Each example is preceded by a header that identifies it. */ /* */ /* The DATA step that creates the data set that most examples */ /* use is at the beginning of the file. You must supply the */ /* name of a SAS data library before running this DATA step. */ /* */ /*****************************************************************/ /* This code creates the data set BUDGET2 in the SAS data library USER. Replace SAS-data-library with the name of a SAS data library. The examples for this book assume that you have assigned the libref USER to the SAS data library that contains BUDGET2. */ libname user 'SAS-data-library'; data budget2; input date:date7. dept $ 9-18 @20 account $ @29 budget @36 actual; actual=actual/100; format budget actual dollar11.2 date date7.; cards; 31mar92 Staff fulltime 130000 12764268 30jun92 Staff fulltime 165000 16634575 31mar92 Staff parttime 40000 4385012 30jun92 Staff parttime 60000 5601896 31mar92 Equipment lease 40000 4000000 30jun92 Equipment lease 40000 4000000 31mar92 Equipment purchase 40000 4828238 30jun92 Equipment purchase 20000 1776915 31mar92 Equipment tape 8000 682942 30jun92 Equipment tape 12000 1142673 31mar92 Equipment sets 7500 834268 30jun92 Equipment sets 7500 807962 31mar92 Equipment maint 10000 754213 30jun92 Equipment maint 12000 1067529 31mar92 Equipment rental 4000 399887 30jun92 Equipment rental 6000 548294 31mar92 Facilities rent 24000 2400000 30jun92 Facilities rent 24000 2400000 31mar92 Facilities utils 5000 422329 30jun92 Facilities utils 3500 344481 31mar92 Facilities supplies 2750 221655 30jun92 Facilities supplies 2750 274248 31mar92 Travel leases 3500 304515 30jun92 Travel leases 4500 388965 31mar92 Travel gas 800 53726 30jun92 Travel gas 1200 98493 31mar92 Other advert 30000 3247698 30jun92 Other advert 30000 3732564 31mar92 Other talent 13500 1298673 30jun92 Other talent 19500 1842464 31mar92 Other musicfee 3000 255050 30jun92 Other musicfee 5000 487595 run; options pagesize=60 linesize=72 nodate pageno=1; /* Chapter 1: Shaping the Report Layout */ /* Listing All Observations and Variables */ /* Report 1: A Report with Character and Numeric Variables */ proc report data=budget2 nowindows; title 'A Report with Character and Numeric Variables'; run; /* Chapter 1: Shaping the Report Layout */ /* Listing All Observations and Variables /* Report 2: A Report with Only Numeric Variables */ proc report data=budget2(keep=budget actual) nowindows; title 'A Report with Only Numeric Variables:'; title2 'All Analysis Variables (by Default)'; run; proc report data=budget2(keep=budget actual) nowindows; define budget / display; define actual / analysis sum; title 'A Report with Only Numeric Variables:'; title2 'Defining One Variable as a Display Variable'; run; /* Chapter 1: Shaping the Report Layout */ /* Specifying and Ordering Columns to Display */ proc report data=budget2 nowindows; column account date budget; title 'Specifying and Ordering Columns to Display'; run; /* Chapter 1: Shaping the Report Layout */ /* Ordering Rows */ proc report data=budget2 nowindows; define date / order order=internal; define dept / order; define account / order descending; define budget / analysis sum; define actual / analysis sum; title 'Ordering Rows'; run; /* Chapter 1: Shaping the Report Layout */ /* Consolidating Multiple Observations into One Row */ /* Report 1: Groups Based on the Value of a Single Variable */ proc report data=budget2 nowindows; column dept budget; define dept / group; define budget / analysis sum; title 'Groups Based on the Value of a Single Variable'; run; /* Chapter 1: Shaping the Report Layout */ /* Consolidating Multiple Observations into One Row */ /* Report 2: Groups Based on the Value of Multiple Variables */ proc report data=budget2 nowindows; column dept account budget; define dept / group; define account / group; define budget / analysis sum; title 'Groups Based on the Value of Multiple Variables'; run; /* Chapter 1: Shaping the Report Layout */ /* Using Variable Values as Column Headers */ /* Report 1: Showing Frequency Counts */ proc report data=budget2 nowindows; column dept date; define dept / group; define date / across order=internal; title 'Showing Frequency Counts'; run; /* Chapter 1: Shaping the Report Layout */ /* Using Variable Values as Column Hearders */ /* Report 2: Sharing a Column with an Analysis Variable */ proc report data=budget2 nowindows; column dept date, budget; define dept / group; define date / across order=internal; define budget / analysis sum; title 'Sharing a Column with an Analysis Variable'; run; /* Chapter 1: Shaping the Report Layout */ /* Using Variable Values as Column Headers */ /* Report 3: Sharing a Column with Multiple Analysis Variables */ proc report data=budget2 nowindows; column dept (budget actual),date; define dept / group; define date / across order=internal width=11; define budget / analysis sum; define actual / analysis sum; title 'Sharing a Column with Multiple Analysis Variables'; run; options pagesize=60 linesize=72 nodate pageno=1; /* Chapter 2: Reports with Statistics */ /* Placing Statistics above or below a Variable */ proc report nowindows data=budget2; column dept (min max),budget; define dept / group; define budget / analysis sum; title 'Placing Statistics above an Analysis Variable'; run; /* Chapter 2: Reports with Statistics */ /* Reporting Multiple Statistics for One Variable */ proc report data=budget2 nowindows; column dept budget=budmin budget=budmax budget=nobs; define dept / group; define budmin / analysis min 'Minimum Budget'; define budmax / analysis max 'Maximum Budget'; define nobs / analysis n format=2. 'N'; title 'Reporting Multiple Statistics for One Variable'; run; /* Chapter 2: Reports with Statistics */ /* Showing Frequency Counts */ /* Report 1: Counting All the Observations that a Row Represents*/ proc report nowindows data=budget2; column dept budget n; define dept / group; define budget / analysis sum; title 'Counting All the Observations that a Row Represents'; run; /* Chapter 2: Reports with Statistics */ /* Showing Frequency Counts */ /* Counting the Observations for Each Value of an Across Variable */ proc report nowindows data=budget2; column dept date,(budget n); define dept / group; define date / across order=internal; define budget / analysis sum; title 'Counting the Observations for Each Value'; title2 'of an Across Variable'; run; /* Chapter 2: Reports with Statistics */ /* Showing Frequency Counts */ /* Combining Report 1 and Report 2 */ proc report nowindows data=budget2; column dept date,(budget n) n; define dept / group; define date / across order=internal '_DATE_'; define budget / analysis sum; title 'Combining Report 1 and Report 2'; run; options pagesize=60 linesize=72 nodate pageno=1; /* Chapter 3: Basic Report Enhancements */ /* Adding Titles */ proc report data=budget2 nowindows; column dept account budget actual; define dept / group; define account / group; define budget / analysis sum; define actual / analysis sum; title 'Financial Information Grouped'; title2 'by Department'; run; /* Chapter 3: Basic Report Enhancements */ /* Adding Footnotes */ /* The null FOOTNOTE statement following this PROC REPORT step */ /* clears the footnote so that it does not show up in the next */ /* example that you run. */ proc report data=budget2 nowindows ps=28; column dept account budget actual; define dept / group; define account / group; define budget / analysis sum; define actual / analysis sum; title 'Financial Information Grouped'; title2 'by Department'; footnote 'All dollar amounts are in Canadian dollars.'; run; footnote; /* Chapter 3: Basic Report Enhancements */ /* Changing the Linesize */ proc report data=budget2 nowindows ls=138; column date dept,(budget actual); define date / group order=internal; define dept / across; define budget / analysis sum; define actual / analysis sum; title 'Changing the Linesize'; run; /* Chapter 3: Basic Report Enhancements */ /* Changing the Pagesize */ proc report data=budget2 nowindows ps=20; title 'Changing the Pagesize'; run; /* Chapter 3: Basic Report Enhancements */ /* Selecting Observations to Process */ /* Both these PROC REPORT steps produce the same report. */ proc report data=budget2 nowindows; where budgetDATE<'; title 'Extending a Column Header with Inequality Signs'; run; /* Chapter 4: Customizing Column Headers */ /* Adding a Blank Line beneath Column Headers */ proc report data=budget2 nowindows headskip; column dept account budget actual; define dept / group; define account / group; define budget / analysis sum; define actual / analysis sum; title 'Adding a Blank Line beneath Column Headers'; run; /* Chapter 4: Customizing Column Headers */ /* Underlining Column Headers */ /* Report 1: Underlining Column Headers and Spaces between Columns */ proc report data=budget2 nowindows headline; column dept account budget actual; define dept / group; define account / group; define budget / analysis sum; define actual / analysis sum; title 'Underlining Column Headers and Spaces between Columns'; run; /* Chapter 4: Customizing Column Headers */ /* Underlining Column Headers */ /* Report 2: Underlining Column Headers without Underlining */ /* the Spaces between Columns */ proc report data=budget2 nowindows; column dept account budget actual; define dept / group 'Department' '--'; define account / group 'Account' '--'; define budget / analysis sum 'Budget' '--'; define actual / analysis sum 'Actual' '--'; title 'Underlining Column Headers without Underlining'; title2 'the Spaces between Columns'; run; /* Chapter 4: Customizing Column Headers */ /* Spanning Multiple Columns with One Customized Column Header */ proc report data=budget2 nowindows; column dept account ('CANADIAN DOLLARS' budget actual); define dept / group; define account / group; define budget / analysis sum; define actual / analysis sum; title 'Spanning Multiple Columns with One Customized Column Header'; run; options pagesize=60 linesize=72 nodate pageno=1; /* Chapter 5: Adding Variables that Are Not in the Input Data Set */ /* Adding a Variable Computed from a Group, Order, Computed, or Display */ /* Variable */ data empinfo; input id $ 1-9 lname $ 11-20 fname $ 22-31 @33 hired date7. salary phone $; format hired date7.; cards; 324987451 Sayre Jay 15nov84 44800 933-2998 596771321 Tolson Andrew 18mar88 41200 929-4800 477562122 Jensen Helga 01feb81 47400 286-2816 894724859 Kulenic Marie 24jun83 41400 493-1472 988427431 Zweerink Anna 07jul85 43700 929-3885 ; proc report data=empinfo nowindows; column lname fname fullname id hired salary phone; define lname / order noprint; define fname / order noprint; define fullname / computed; define id / display; define hired / display; define salary / analysis sum; define phone / display; compute fullname / char length=20; fullname=trim(fname)||' '||lname; endcomp; title 'Adding a Variable Based on a Group, Order,'; title2 'Computed, or Display Variable'; run; /* Chapter 5: Adding Variables that Are Not in the Input Data Set */ /* Adding a Variable Computed from a Statistic */ proc report data=budget2 nowindows; column dept account budget actual balance; define dept / group; define account / group; define budget / analysis sum; define actual / analysis sum; define balance / computed format=dollar11.2; compute balance; balance=budget.sum-actual.sum; endcomp; title 'Adding a Variable Based on a Statistic'; run; /* Chapter 5: Adding Variables that Are Not in the Input Data Set */ /* Adding a Variable Computed from a Variable that Shares a Column */ /* with an Across Variable */ /* Report 1: When the Computed Variable Does Not Share a Column */ /* with an Across Variable */ proc report data=budget2 nowindows; column dept account date,budget ratio; define dept / group; define account / group; define date / across order=internal; define budget / analysis sum; define ratio / computed format=5.2; compute ratio; ratio=_c3_/_c4_; endcomp; title 'When the Computed Variable Does Not Share the Column'; run; /* Chapter 5: Adding Variables that Are Not in the Input Data Set */ /* Adding a Variable Computed from a Variable that Shares a Column */ /* with an Across Variable */ /* Report 2: When the Computed Variable Does Share a Column */ proc report data=budget2 nowindows ls=100; column dept account date,(budget actual qtrbal); define dept / group; define account / group; define date / across order=internal; define budget / analysis sum; define actual / analysis sum; define qtrbal / computed format=dollar11.2 width=11; compute qtrbal; _c5_=_c3_-_c4_; _c8_=_c6_-_c7_; endcomp; title 'When the Computed Variable Does Share a Column'; run; /* Chapter 5: Adding Variables that Are Not in the Input Data Set */ /* Adding a Character Variable */ proc report data=budget2 nowindows; column dept account budget actual over; define dept / group; define account / group; define budget / analysis sum; define actual / analysis sum; define over / computed format=$1. width=4; compute over / character length=1; if budget.sum-actual.sum<0 then over='*'; else over=' '; endcomp; title 'Adding a Character Variable'; run; options pagesize=60 linesize=72 nodate pageno=1; /* Chapter 6: Working with Groups of Observations */ /* Producing a Separate Page for Each Group */ /* Report 1: Inserting a Page Break between Groups */ proc report data=budget2 nowindows; column dept account budget actual; define dept / group; define account / group; define budget / analysis sum; define actual / analysis sum; break after dept / page; title 'Inserting a Page Break between Groups'; run; /* Chapter 6: Working with Groups of Observations */ /* Producing a Separate Page for Each Group */ /* Report 2: Using a Group Variable as a BY Variable */ options byline; proc sort data=budget2 out=sorted; by dept; run; proc report data=sorted nowindows; column dept account budget actual; define dept / group; define account / group; define budget / analysis sum; define actual / analysis sum; by dept; title 'Using a Group Variable as a BY Variable'; run; /* Chapter 6: Working with Groups of Observations */ /* Inserting a Blank Line between Groups */ proc report data=budget2 nowindows; column dept account budget actual; define dept / group; define account / group; define budget / analysis sum; define actual / analysis sum; break after dept / skip; title 'Inserting a Blank Line between Groups'; run; /* Chapter 6: Working with Groups of Observations */ /* Inserting Multiple Blank Lines between Groups */ proc report data=budget2 nowindows; column dept account budget actual; define dept / group; define account / group; define budget / analysis sum; define actual / analysis sum; compute after dept; line ' '; line ' '; line ' '; endcomp; title 'Inserting Multiple Blank Lines between Groups'; run; /* Chapter 6: Working with Groups of Observations */ /* Summarizing Variables and Statistics for Groups */ proc report data=budget2 nowindows; column dept account budget actual; define dept / group; define account / group; define budget / analysis sum; define actual / analysis sum; break after dept / skip summarize; title 'Summarizing Variables and Statistics for Groups'; run; /* Chapter 6: Working with Groups of Observations */ /* Overlining Summary Information */ proc report data=budget2 nowindows; column dept account budget actual; define dept / group; define account / group; define budget / analysis sum; define actual / analysis sum; break after dept / skip summarize ol; title 'Overlining Summary Information'; run; /* Chapter 6: Working with Groups of Observations */ /* Underlining Summary Information */ proc report data=budget2 nowindows; column dept account budget actual; define dept / group; define account / group; define budget / analysis sum; define actual / analysis sum; break after dept / skip summarize ul; title 'Underlining Summary Information'; run; /* Chapter 6: Working with Groups of Observations */ /* Summarizing the Value of the Group Variable in the Summary */ /* Information */ proc report data=budget2 nowindows; column dept account budget actual; define dept / group; define account / group; define budget / analysis sum; define actual / analysis sum; break after dept / skip summarize suppress; title 'Suppressing the Value of the Group Variable '; title2 'in the Summary Information'; run; /* Chapter 6: Working with Groups of Observations */ /* Changing the Value of a Character Variable */ /* in the Summary Information */ proc report data=budget2 nowindows; column dept account budget actual; define dept / group; define account / group; define budget / analysis sum; define actual / analysis sum; break after dept / skip summarize; compute after dept; dept='Subtotal:'; endcomp; title 'Changing the Value of a Character Variable'; title2 'in the Summary Information'; run; /* Chapter 6: Working with Groups of Observations */ /* Specifying Text and Variables between Groups */ proc report data=budget2 nowindows; column dept account budget; define dept / group; define account / group; define budget / analysis sum; compute after dept; line ' '; line 'The budget for the ' dept $10. ' department is:' budget.sum dollar9. '.'; line ' '; endcomp; title 'Specifying Text and Variables between Groups'; run; /* Chapter 6: Working with Groups of Observations */ /* Controlling the Amount of Space Used to Write */ /* a Character Variable */ proc report data=budget2 nowindows; column dept account budget; define dept / group; define account / group; define budget / analysis sum; compute after dept; line ' '; len=length(dept); line 'The ' dept $varying. len ' budget is: ' budget.sum dollar9. '.'; line ' '; endcomp; title 'Controlling the Amount of Space Used to Write'; title2 'a Character Variable'; run; /* Chapter 6: Working with Groups of Observations */ /* Controlling the Amount of Space Used to Write */ /* a Numeric Variable */ proc report data=budget2 nowindows; column dept account budget; define dept / group; define account / group; define budget / analysis sum; compute after dept; line ' '; len1=length(dept); makechar=left(put(budget.sum,dollar9.)); len2=length(makechar); line 'The ' dept $varying. len1 ' budget is: ' makechar $varying. len2 '.'; line ' '; endcomp; title 'Controlling the Amount of Space Used to Write'; title2 'a Numeric Variable'; run; /* Chapter 6: Working with Groups of Observations */ /* Controlling the Horizontal Position of Text between Groups */ proc report data=budget2 nowindows; column dept account budget; define dept / group; define account / group; define budget / analysis sum; compute after dept; line ' '; len=length(dept); line @12 'The ' dept $varying. len ' budget is: ' budget.sum dollar9. '.'; line ' '; endcomp; title 'Controlling the Horizontal Position of Text between Groups'; run; /* Chapter 6: Working with Groups of Observations */ /* Initializing Variables for Each Group */ /* */ proc report data=budget2 nowindows; column dept account budget actual balance; define dept / group; define account / group; define budget / analysis sum; define actual / analysis sum; define balance / computed format=dollar11.2; compute before dept; count=0; endcomp; compute balance; balance=budget.sum-actual.sum; if balance<0 and account ne ' ' then count+1; endcomp; compute after dept; line ' '; line count 1. ' accounts exceeded their budgets.'; line ' '; endcomp; title 'Initializing Variables for Each Group'; run; /* Chapter 6: Working with Groups of Observations */ /* Placing Conditional Text between Groups */ proc report data=budget2 nowindows; column dept account budget actual balance; define dept / group; define account / group; define budget / analysis sum; define actual / analysis sum; define balance / computed format=dollar11.2; compute balance; balance=budget.sum-actual.sum; if balance<0 then over='yes'; endcomp; compute before dept; over='no'; endcomp; compute after dept; length text1 $ 60; line ' '; if over='yes' then text1='At least one account in this department overspent its budget.'; else text1='All accounts in this department were within their budgets.'; line text1 $60.; line ' '; endcomp; title 'Placing Conditional Text between Groups'; run; /* Chapter 6: Working with Groups of Observations */ /* Controlling Whether Statements in a Compute Block Execute */ /* between Groups */ proc report data=budget2 nowindows; column dept account budget actual balance; define dept / group; define account / group; define budget / analysis sum; define actual / analysis sum; define balance / computed format=dollar11.2; compute before dept; count=0; endcomp; compute balance; balance=budget.sum-actual.sum; if balance<0 and account ne ' ' then count+1; endcomp; compute after dept; line ' '; line count 1. ' accounts exceeded their budgets.'; line ' '; endcomp; title 'Controlling Whether Statements in a Compute Block Execute'; title2 'between Groups'; run; options pagesize=60 linesize=72 nodate pageno=1; /* Chapter 7: Working with the Report as a Whole */ /* Summarizing Variables and Statistics for the Whole Report */ proc report data=budget2 nowindows; column dept account budget actual; define dept / group; define account / group; define budget / analysis sum; define actual / analysis sum; rbreak after / summarize; title 'Summarizing Variables and Statistics for the Whole Report'; run; /* Chapter 7: Working with the Report as a Whole */ /* Overlining Summary Information */ proc report data=budget2 nowindows; column dept account budget actual; define dept / group; define account / group; define budget / analysis sum; define actual / analysis sum; rbreak after / summarize ol; title 'Overlining Summary Information'; run; /* Chapter 7: Working with the Report as a Whole */ /* Underlining Summary Information */ proc report data=budget2 nowindows; column dept account budget actual; define dept / group; define account / group; define budget / analysis sum; define actual / analysis sum; rbreak before / summarize ul; title 'Underlining Summary Information'; run; /* Chapter 7: Working with the Report as a Whole */ /* Inserting a Blank Line after Summary Information */ /* at the Beginning of a Report */ proc report data=budget2 nowindows; column dept account budget actual; define dept / group; define account / group; define budget / analysis sum; define actual / analysis sum; rbreak before / summarize skip; title 'Inserting a Blank Line after Summary Information'; title2 'at the Beginning of a Report'; run; /* Chapter 7: Working with the Report as a Whole */ /* Inserting Multiple Blank Lines after Summary Information */ /* at the Beginning of a Report */ proc report data=budget2 nowindows; column dept account budget actual; define dept / group; define account / group; define budget / analysis sum; define actual / analysis sum; rbreak before / summarize; compute before; line ' '; line ' '; endcomp; title 'Inserting Multiple Blank Lines after Summary Information'; title2 'at the Beginning of a Report'; run; /* Chapter 7: Working with the Report as a Whole */ /* Changing the Value of a Character Variable */ /* in the Summary Information */ proc report data=budget2 nowindows; column dept account budget actual; define dept / group; define account / group; define budget / analysis sum; define actual / analysis sum; rbreak after / summarize; compute after; dept='Total:'; endcomp; title 'Changing the Value of a Character Variable'; title2 'in the Summary Information'; run; /* Chapter 7: Working with the Report as a Whole */ /* Specifying Text and Variable Values at the Beginning or End */ /* of a Report */ proc report data=budget2 nowindows; column dept account budget; define dept / group; define account / group; define budget / analysis sum; compute after; line ' '; line 'The budget for the entire company is ' budget.sum dollar9. '.'; line ' '; endcomp; title 'Specifying Text and Variable Values at the Beginning or End'; title2 'of a Report'; run; /* Chapter 7: Working with the Report as a Whole */ /* Controlling the Horizontal Position of Text */ /* at the Beginning or End of a Report */ proc report data=budget2 nowindows; column dept account budget; define dept / group; define account / group; define budget / analysis sum; compute after; line ' '; line @12 'The budget for the entire company is ' budget.sum dollar8. '.'; line ' '; endcomp; title 'Controlling the Horizontal Position of Text'; title2 'at the Beginning or End of a Report'; run; /* Chapter 7: Working with the Report as a Whole */ /* Initializing Variables at the Beginning of a Report */ proc report data=budget2 nowindows; column dept account budget actual balance; define dept / group; define account / group; define budget / analysis sum; define actual / analysis sum; define balance / computed format=dollar11.2; compute before; count=0; endcomp; compute balance; balance=budget.sum-actual.sum; if balance<0 and account ne ' ' then count+1; endcomp; compute after; line ' '; line count 1. ' accounts exceeded their budgets.'; line ' '; endcomp; title 'Initializing Variables at the Beginning of a Report'; run; /* Chapter 7: Working with the Report as a Whole */ /* Placing Conditional Text at the Beginning or End */ /* of a Report */ /* In this case some accounts are over their budgets. */ proc report data=budget2 nowindows; column dept account budget actual balance; define dept / group; define account / group; define budget / analysis sum; define actual / analysis sum; define balance / computed format=dollar11.2; compute balance; balance=budget.sum-actual.sum; if balance<0 then over='yes'; endcomp; compute after; line ' '; length text1 $42.; if over='yes' then text1='At least one account overspent its budget.'; else text1='All accounts were within their budgets.'; line text1 $42.; endcomp; title 'Placing Conditional Text at the Beginning or End'; title2 'of a Report'; run; /* In this case, no account is over its budget. */ proc report data=budget2 nowindows; where dept='Facilities' or dept='Travel'; column dept account budget actual balance; define dept / group; define account / group; define budget / analysis sum; define actual / analysis sum; define balance / computed format=dollar11.2; compute balance; balance=budget.sum-actual.sum; if balance<0 then over='yes'; endcomp; compute after; line ' '; length text1 $42.; if over='yes' then text1='At least one account overspent its budget.'; else text1='All accounts were within their budgets.'; line text1 $42.; endcomp; title 'Placing Conditional Text at the Beginning or End'; title2 'of a Report'; run; /* Chapter 7: Working with the Report as a Whole */ /* Controlling Whether Statements in a Compute Block */ /* Execute at the Beginning and End of a Report */ proc report data=budget2 nowindows; column dept account budget actual balance; define dept / group; define account / group; define budget / analysis sum; define actual / analysis sum; define balance / computed format=dollar11.2; compute before; count=0; endcomp; compute balance; balance=budget.sum-actual.sum; if balance<0 and account ne ' ' then count+1; endcomp; compute after; line ' '; line count 1. ' accounts exceeded their budgets.'; line ' '; endcomp; title 'Controlling Whether Statements in a Compute Block'; title2 'Execute at the Beginning and End of a Report'; run; options pagesize=60 linesize=72 nodate pageno=1; /* Chapter 8: Calculating Percentages */ /* Calculating Percentages within Groups */ proc report data=budget2 nowindows; column dept account budget pctdept; define dept / group; define account / group; define budget / analysis sum; define pctdept / computed format=percent8.1; compute before dept; deptbud=budget.sum; endcomp; compute pctdept; pctdept=budget.sum/deptbud; endcomp; break after dept / skip summarize; title 'Calculating Percentages within Groups'; run; /* Chapter 8: Calculating Percentages */ /* Calculating Percentages over All Groups */ proc report data=budget2 nowindows; column dept account budget pctcomp; define dept / group; define account / group; define budget / analysis sum; define pctcomp / computed format=percent8.1; compute before; compbud=budget.sum; endcomp; compute pctcomp; pctcomp=budget.sum/compbud; endcomp; break after dept / skip summarize; rbreak after / summarize; title 'Calculating Percentages over All Groups'; run; /* Chapter 8: Calculating Percentages */ /* Calculating Cumulative Percentages within Groups */ proc report data=budget2 nowindows; column dept account budget pctdept cumpct; define dept / group; define account / group; define pctdept / computed format=percent8.1; define cumpct / computed format=percent8.1; compute before dept; deptbud=budget.sum; cume=0; endcomp; compute pctdept; pctdept=budget.sum/deptbud; if account ne ' ' then cume+pctdept; endcomp; compute cumpct; cumpct=cume; endcomp; break after dept / skip; title 'Calculating Cumulative Percentages within Groups'; run; /* Chapter 8: Calculating Percentages */ /* Calculating Cumulative Percentages for the Whole Report */ proc report data=budget2 nowindows; column dept account budget pctcomp cumpct; define dept / group; define account / group; define budget / analysis sum; define pctcomp / computed format=percent8.1; define cumpct / computed format=percent8.1; compute before; compbud=budget.sum; cume=0; endcomp; compute pctcomp; pctcomp=budget.sum/compbud; if account ne ' ' then cume+pctcomp; endcomp; compute cumpct; cumpct=cume; endcomp; break after dept / skip; title 'Calculating Cumulative Percentages for the Whole Report'; run; options pagesize=60 linesize=72 nodate pageno=1; /* Chapter 9: The REPORT Language */ /* Examples */ /* Specifying and Ordering Columns to Display with the Column Statement */ proc report data=budget2 nowindows; column account date budget; title 'Budgets for Each Account in Each Quarter'; run; /* Chapter 9: The REPORT Language */ /* Examples */ /* Ordering Rows with the ORDER and ORDER= Options */ proc report data=budget2 nowindows; column dept account date budget actual; define dept / order; define account / order; define date / order order=internal descending; define budget / analysis sum; define actual / analysis sum; title 'Budgets and Expenditures for All Accounts'; run; /* Chapter 9: The REPORT Language */ /* Examples */ /* Grouping Observations with the GROUP Option and an Analysis Variable */ proc report data=budget2 nowindows; column dept budget; define dept / group; define budget / analysis sum; title 'Departmental Budgets'; run; /* Chapter 9: The REPORT Language */ /* Examples */ /* Creating Column Headers from Variable Values with the ACROSS Option */ proc report data=budget2 nowindows; column dept date,(budget actual); define dept / group; define date / across order=internal; define budget / analysis sum; define actual / analysis sum; title 'Departmental Budgets and Expenditures for Each Quarter'; run; /* Chapter 9: The REPORT Language */ /* Examples */ /* Printing All Values for a Long Row on Consecutive Lines with the Wrap */ /* Option */ /* The first PROC REPORT step shows the report without the WRAP option */ /* so that you can compare the results. */ /* The second PROC REPORT step is identical to the first except that */ /* it used the NAMED and WRAP options in the PROC REPORT statement. */ proc report data=budget2 nowindows ls=64; where dept='Equipment'; column dept account date,(budget actual); define dept / group; define account / group; define date / across order=internal; define budget / analysis sum ; define actual / analysis sum; break after account / skip; title 'Amounts Budgeted and Spent for Equipment'; title2 'for the First and Second Quarters'; run; proc report data=budget2 nowindows ls=64 named wrap; where dept='Equipment'; column dept account date,(budget actual); define dept / group; define account / group; define date / across; define budget / analysis sum; define actual / analysis sum; break after account / skip; title 'Amounts Budgeted and Spent for Equipment'; title2 'for the First and Second Quarters'; run; /* Chapter 9: The REPORT Language */ /* Examples */ /* Creating a Group for Missing Values with the MISSING Option */ /* The first PROC REPORT step shows the report without the MISSING option */ /* so that you can compare the results. */ /* The second PROC REPORT step is identical to the first except that */ /* it used the MISSING option in the PROC REPORT statement. */ data testmiss; set budget2; if dept='Equipment' then dept=' '; run; proc report data=testmiss nowindows; column dept budget; define dept / group; define budget / analysis sum; rbreak after / ol summarize; title 'Sum of Departmental Budgets'; run; proc report data=testmiss nowindows missing; column dept budget; define dept / group; define budget / analysis sum; rbreak after / ol summarize; title 'Sum of Departmental Budgets'; run; /* Chapter 9: The REPORT Language */ /* Examples */ /* Customizing Column Headers */ proc report data=budget2 nowindows; column dept account ('_Canadian Dollars_' budget actual); define dept / group 'Department' '=='; define account / group 'Account' '=='; define budget / analysis sum 'Amount/in Budget' '=='; define actual / analysis sum 'Amount Spent' '=='; title 'Budgets and Expenditures for Each Account'; run; /* Chapter 9: The REPORT Language */ /* Examples */ /* Making Multipanel Reports with the PANELS= Option */ proc report data=budget2 nowindows panels=99 ps=19 ls=100; column date dept account budget; title 'Departmental Budgets'; run; /* Chapter 9: The REPORT Language */ /* Examples */ /* Adding Variables to a Report with a COMPUTE Block */ proc report data=budget2 nowindows; column dept account budget actual balance; define dept / group; define account / group; define budget / analysis sum; define actual / analysis sum; define balance / computed format=dollar11.2; compute balance; balance=budget.sum-actual.sum; endcomp; title 'Account Balances'; run; /* Chapter 9: The REPORT Language */ /* Examples */ /* Creating Default Group Summaries with the BREAK Statement */ proc report data=budget2 nowindows; column dept account budget actual balance; define dept / group; define account / group; define budget / analysis sum; define actual / analysis sum; define balance / computed format=dollar11.2; compute balance; balance=budget.sum-actual.sum; endcomp; break after account / skip; break after dept / ol ul summarize suppress skip; title 'Departmental Budgets, Expenditures, and Balances'; run; /* Chapter 9: The REPORT Language */ /* Examples */ /* Creating a Default Report Summary with the RBREAK Statement */ proc report data=budget2 nowindows; column dept account budget actual balance; define dept / group; define account / group; define budget / analysis sum; define actual / analysis sum; define balance / computed format=dollar11.2; compute balance; balance=budget.sum-actual.sum; endcomp; rbreak after / dol dul summarize; title 'Company Budget, Expenditures, and Balance'; run; /* Chapter 9: The REPORT Language */ /* Examples */ /* Creating Customized Group Summaries with the COMPUTE Statement */ proc report data=budget2 nowindows; column dept account budget actual balance; define dept / group; define account / group; define budget / analysis sum; define actual / analysis sum; define balance / computed format=dollar11.2; compute balance; balance=budget.sum-actual.sum; endcomp; compute after dept; line ' '; line @15 51*'-'; line @15 '| The budget for this department was ' budget.sum dollar11.2'. |'; line @15 '| The department spent ' actual.sum dollar11.2 '.' @65 '|'; line @15 51*'-'; line ' '; endcomp; title 'Departmental Budgets, Expenditures, and Balances'; run; /* Chapter 9: The REPORT Language */ /* Examples */ /* Wrapping the Value of a Character Variable across Multiple Rows */ proc report data=budget2 nowindows; column dept budget actual comment; define dept / group; define budget / analysis sum; define actual / analysis sum; define comment / computed width=20 flow; compute comment / char length=41; if budget.sum-actual.sum < 0 then comment='This department has overdrawn its budget.'; else comment=' '; endcomp; title 'Report of Departments that Overspent Their Budgets'; run; /* Chapter 9: The REPORT Language */ /* Examples */ /* Suppressing the Display of an Item with the NOPRINT Option */ proc report data=budget2 nowindows; column dept account budget actual balance; define dept / group; define account / group; define budget / analysis sum noprint; define actual / analysis sum noprint; define balance / computed format=dollar11.2; compute balance; balance=budget.sum-actual.sum; endcomp; title 'Account Balances'; run; /* Chapter 9: The REPORT Language */ /* Examples */ /* Writing a Report for Use in the Windowing Environment */ /* Creating the Report Definition that the EXECUTE Command Loads */ proc report data=budget2 nowindows outrept=user.reports.details; column dept account budget actual balance; define dept / group; define account / group; define budget / analysis sum; define actual / analysis sum; define balance / computed format=dollar11.2; compute balance; balance=budget.sum-actual.sum; endcomp; run; /* Building the Report to Use in a Windowing Environment */ proc report data=budget2 nowindows outrept=user.reports.interact; column dept budget actual balance; define dept / group; define budget / analysis sum noprint; define actual / analysis sum noprint; define balance / computed format=dollar11.2; compute balance; balance=budget.sum-actual.sum; if balance<0 then call define(_col_,'color','yellow'); string='rload user.reports.details; where dept="'||dept||'"'; call define('balance','command',string); endcomp; break after dept / skip; title 'Summary of Departmental Budgets'; run; /* Using the Report Definition in the Windowing Environment */ /* These statements will open the REPORT window. */ proc report data=budget2 windows report=user.reports.interact; title 'Summary of Department Budgets'; run;