Presentation is loading. Please wait.

Presentation is loading. Please wait.

Copyright © 2004, SAS Institute Inc. All rights reserved. SAS is a registered trademark or trademark of SAS Institute Inc. in the USA and other countries.

Similar presentations


Presentation on theme: "Copyright © 2004, SAS Institute Inc. All rights reserved. SAS is a registered trademark or trademark of SAS Institute Inc. in the USA and other countries."— Presentation transcript:

1 Copyright © 2004, SAS Institute Inc. All rights reserved. SAS is a registered trademark or trademark of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. Other brand and product names are registered trademarks or Trademarks of their respective companies Compute Blocks Revealed Sandy McNeill

2 Copyright © 2003, SAS Institute Inc. All rights reserved. 2 Take all the guesswork out of finding the answers to life's more perplexing questions.

3 Copyright © 2003, SAS Institute Inc. All rights reserved. 3 Agenda  Uses of Compute Blocks  What do Compute Blocks look like?  Rules  Tricks/Traps  Questions

4 Copyright © 2003, SAS Institute Inc. All rights reserved. 4 What are the uses of Compute Blocks?

5 Copyright © 2003, SAS Institute Inc. All rights reserved. 5 Compute Block for Computed Variable

6 Copyright © 2003, SAS Institute Inc. All rights reserved. 6 Compute Block for Traffic Lighting

7 Copyright © 2003, SAS Institute Inc. All rights reserved. 7 Compute Block for Line Statements

8 Copyright © 2003, SAS Institute Inc. All rights reserved. 8 Compute Block Tied to Break

9 Copyright © 2003, SAS Institute Inc. All rights reserved. 9 What do Compute Blocks look like?

10 Copyright © 2003, SAS Institute Inc. All rights reserved. 10 As Simple As…. define balance / computed ; compute balance; balance=budget-actual; endcomp; compute before; totalaccts = 0; endcomp; OR

11 Copyright © 2003, SAS Institute Inc. All rights reserved. 11 As Cool As…. compute yrtodate; yrtodate=budget.sum-actual.sum; if yrtodate > 0 then call define( _col_, 'style', 'style={background=yellow}'); endcomp;

12 Copyright © 2003, SAS Institute Inc. All rights reserved. 12 As Complicated As….. compute after dept; pctbud = round((budget.sum/totalbud)*100); updept = upcase(dept); line pctbud 2. '% of YTD budget allocated to ' updept $varying. len '.'; if yrtodate < 0 then do; pctover = abs(round((yrtodate/budget.sum)*100)); text2 = ‘Over budget by ' || trim(left(put(pctover,3.0))) || '%.'; end; else text2=' '; line text2 $80.; endcomp;

13 Copyright © 2003, SAS Institute Inc. All rights reserved. 13 Rules of Operation

14 Copyright © 2003, SAS Institute Inc. All rights reserved. 14 Evaluation / Execution COL 1COL 2COL 3COL 4 1 2 3

15 Copyright © 2003, SAS Institute Inc. All rights reserved. 15 Values to the Left COL 1COL 2COL 3COL 4 Column 3 is a computed column Can’t use COL4 value in COL3 BUT….. You can write to columns to the left

16 Copyright © 2003, SAS Institute Inc. All rights reserved. 16 Analysis Variable “Dot” Syntax Weight.sum Height.median Weight.min Weight.max

17 Copyright © 2003, SAS Institute Inc. All rights reserved. 17 Where can you use a Compute Block?  Before / After report Compute before; Compute after;  For any report variable Compute weight;/* analysis variable */ Compute age;/* group or order variable */ Compute balance; /* computed variable */

18 Copyright © 2003, SAS Institute Inc. All rights reserved. 18 Where or With What Variable (cont)  Before / After a grouping Compute before age; Compute after age;  Before / After Page or Table Compute before _page_; Compute after _page_;

19 Copyright © 2003, SAS Institute Inc. All rights reserved. 19 Four Meanings of Analysis Vars  Compute before/after _page_  Detail lines  Compute before/after Grouping  Compute before/after (report)

20 Copyright © 2003, SAS Institute Inc. All rights reserved. 20 Compute Before / After _PAGE_ Compute Before _page_; Line ‘Budget.sum is ‘ budget.sum dollar12.2; Endcomp; Output looks like: Budget.sum is $40,000.00

21 Copyright © 2003, SAS Institute Inc. All rights reserved. 21 Compute Before / After _PAGE_ Compute Before _page_; Line ‘Budget.sum is ‘ budget.sum dollar12.2; Endcomp; Output looks like: Budget.sum is $40,000.00 Where does REPORT get the value for Budget.sum ?

22 Copyright © 2003, SAS Institute Inc. All rights reserved. 22 Answer: The value for budget.sum in the first detail line

23 Copyright © 2003, SAS Institute Inc. All rights reserved. 23 Detail Lines GROUP ANALYSISComputed 55 10 15 30 Detail 1 Detail 2 Detail 3 Summary Compute Computed; Computed = Analysis.sum; Endcomp;

24 Copyright © 2003, SAS Institute Inc. All rights reserved. 24 Detail Lines GROUP ANALYSISComputed 55 10 15 30 Detail 1 Detail 2 Detail 3 Summary Compute Computed; Computed = Analysis.sum; Endcomp; Where does REPORT get the value for Analysis.sum ?

25 Copyright © 2003, SAS Institute Inc. All rights reserved. 25 Detail Lines GROUP ANALYSISComputed 55 10 15 30 Detail 1 Detail 2 Detail 3 Summary Compute Computed; Computed = Analysis.sum; Endcomp; Answer: From the value of Analysis.sum on the same detail line.

26 Copyright © 2003, SAS Institute Inc. All rights reserved. 26 Compute before/after Grouping GROUP1GROUP2ANALYSISComputed XXXXYYYY55 ZZZZ10 Compute After Group1. Val = 15 Detail 1 Detail 2 Break after group1 / summarize; Compute after Group1; Line ‘Compute After Group1. Val = ‘ analysis.sum 5.; Endcomp; Compute After Group1

27 Copyright © 2003, SAS Institute Inc. All rights reserved. 27 Compute before/after Grouping GROUP1GROUP2ANALYSISComputed XXXXYYYY55 ZZZZ10 Compute After Group1. Val = 15 Detail 1 Detail 2 Break after group1 / summarize; Compute after Group1; Line ‘Compute After Group1. Val = ‘ analysis.sum 5.; Endcomp; Compute After Group1 Where does REPORT get the value for Analysis.sum ?

28 Copyright © 2003, SAS Institute Inc. All rights reserved. 28 Compute before/after Grouping GROUP1GROUP2ANALYSISComputed XXXXYYYY55 ZZZZ10 Compute After Group1. Val = 15 Detail 1 Detail 2 Break after group1 / summarize; Compute after Group1; Line ‘Compute After Group1. Val = ‘ analysis.sum 5.; Endcomp; Compute After Group1 Answer: From the summarized value of Analysis.sum for this grouping. NOTE: Summary is implicitly done by REPORT.

29 Copyright © 2003, SAS Institute Inc. All rights reserved. 29

30 Copyright © 2003, SAS Institute Inc. All rights reserved. 30 Compute after ; GROUP1GROUP2ANALYSIS XXXXYYYY5 ZZZZ10 AAAABBBB15 Line Stmt After Report. Val = 30 Detail 1 Detail 2 Report Summary RBREAK after / summarize; Compute after; Line ‘Line Stmt after Report. Val = ‘ analysis.sum 5.; Endcomp; Detail 3

31 Copyright © 2003, SAS Institute Inc. All rights reserved. 31 Compute after ; GROUP1GROUP2ANALYSIS XXXXYYYY5 ZZZZ10 AAAABBBB15 Line Stmt After Report. Val = 30 Detail 1 Detail 2 Report Summary RBREAK after / summarize; Compute after; Line ‘Line Stmt after Report. Val = ‘ analysis.sum 5.; Endcomp; Detail 3 Where does REPORT get the value for Analysis.sum ?

32 Copyright © 2003, SAS Institute Inc. All rights reserved. 32 Compute after ; GROUP1GROUP2ANALYSIS XXXXYYYY5 ZZZZ10 AAAABBBB15 Line Stmt After Report. Val = 30 Detail 1 Detail 2 Report Summary RBREAK after / summarize; Compute after; Line ‘Line Stmt after Report. Val = ‘ analysis.sum 5.; Endcomp; Detail 3 Answer: From the summarized value of Analysis.sum for this report. NOTE: Summary is implicitly done by REPORT.

33 Copyright © 2003, SAS Institute Inc. All rights reserved. 33 Traps and Tricks

34 Copyright © 2003, SAS Institute Inc. All rights reserved. 34 “Dot” Syntax Analysis Variable. Statistic

35 Copyright © 2003, SAS Institute Inc. All rights reserved. 35 Computed Columns Under Across QUARTER DEPTQTR 1QTR 2 SalesActualBalanceSalesActualBalance Compute Balance; _c4_ = _c2_ + _c3_; _c7_ = _c5_ + _c6_; Endcomp; Column dept quarter,(sales actual balance); Define balance / computed;

36 Copyright © 2003, SAS Institute Inc. All rights reserved. 36 Computed Columns Under Across QUARTER DEPTQTR 1QTR 2 SalesActualBalanceSalesActualBalance Compute Dummy; _c4_ = _c2_ + _c3_; _c7_ = _c5_ + _c6_; Endcomp; Column dept quarter,(sales actual balance) dummy; Define balance / computed; Define dummy / noprint;

37 Copyright © 2003, SAS Institute Inc. All rights reserved. 37 Computed Columns Don’t Summarize GROUP ANALYSISCOMPUTED COLUMN 5 5 5 5 Detail 1 Detail 2 Detail 3 Summary Compute computedColumn; computedColumn = 5; Endcomp; Rbreak after / summarize;

38 Copyright © 2003, SAS Institute Inc. All rights reserved. 38 Computed Columns Don’t Summarize GROUP1GROUP2ANALYSIS COMPUTED COLUMN XXXXAAAA5 YYYYBBBB5 CCCC5 15 Detail 1 Detail 2 Detail 3 Summary Compute computedColumn; If _break_ = ‘ ‘ then do; ComputedColumn = 5; total = total + ComputedColumn; End; Else computedColumn = total; Endcomp;

39 Copyright © 2003, SAS Institute Inc. All rights reserved. 39 Summary  Uses of Compute Blocks  What do Compute Blocks look like?  Rules  Tricks/Traps

40 Copyright © 2003, SAS Institute Inc. All rights reserved. 40


Download ppt "Copyright © 2004, SAS Institute Inc. All rights reserved. SAS is a registered trademark or trademark of SAS Institute Inc. in the USA and other countries."

Similar presentations


Ads by Google