Noreen Redden FOCUS Users of New England 2012 FOCWizards and Focal Point Information Builders Off to See the Wizards 1
Techniques – Of Course 2
Techniques 3 Customer Asked: A Report totals sales by Product Code within Region. We also need to get the total Sales for each Product Code, regardless of Region. Can I do this all in One Report, and one pass through the Data? Our Answer: Of course, there is always the McGyver Way. Previous Limitations of McGyver Using a Generated Key field, means that we need different headings for the within Region report and the totals report. In previous releases, we did this with SUBHEAD, but that required also spelling out column headings, difficult with ACROSS Also, some of the ACROSS values may be empty for particular regions, causing yet more complications.
McGyver 4 McGyver Technique: 1. Create a file with Counters. 2. Duplicate each Sales record as many times as needed to create the different types of reports 3. Use DEFINE to specify parameters for each section. Sales Record counter Sale #1 REGION X Copy 1Copy 2 Sale #2 REGION Y Copy 1Copy 2 DEFINE SRT REGION XREGION YTOTAL
McGyver 5 TABLE FILE SYSCOLUM PRINT COMPUTE CONTROL/A1 = 'X'; TBNAME WHERE RECORDLIMIT EQ 1 ON TABLE SAVE AS FOCMCGYV END JOIN CONTROL WITH DIV IN EMPDATA TO BLANK IN FOCMCGYV AS AJ END DEFINE FILE EMPDATA CONTROL/A1 WITH DIV = 'X'; SRT/A13 = IF ORDER EQ 1 THEN AREA ELSE 'Total'; CLASS/A3 = EDIT(JOBCLASS,'999'); END 1 2 3
McGyver 6 SET HIDENULLACRS = ON TABLE FILE EMPDATA SUM SALARY ACROSS CLASS AS 'Job Class' BY ORDER NOPRINT PAGE-BREAK BY SRT NOPRINT PAGE-BREAK BY DEPT IF ORDER EQ 1 OR 2 HEADING "Salaries For Area: <SRT " WHEN ORDER EQ 1; HEADING "Salaries For All Areas " WHEN ORDER EQ 2; END
Salaries For Area: NORTH EASTERN Job Class DEPT CUSTOMER SUPPORT$62, $19, MARKETING.$139, SALES.$82, Salaries For Area: SOUTH EASTERN Job Class DEPT CONSULTING.$85, CUSTOMER SUPPORT$62, MARKETING... PERSONNEL$80, PROGRAMMING & DVLPMT..$49, McGyver 7
Salaries For All Areas Job Class DEPT ACCOUNTING $224, ADMIN SERVICES... CONSULTING.$126, CUSTOMER SUPPORT $179, MARKETING $62, PERSONNEL $125, PROGRAMMING & DVLPMT..$182, SALES$239, McGyver 8
Job Class $58, $56, $19, $508, $91, $156, McGyver 9
Techniques 10 Customer Asked: I want to combine values from multiple records into a single line (or lines) for the same key value. Our Answer: If the records are sorted by the key, use DEFINE followed by SUM:, if not sorted, COMPUTE with WHERE TOTAL As it is Built key rec1comment key rec1comment rec2comment key rec1comment rec2comment rec3comment * After SUM or WHERE TOTAL key rec1comment rec2comment rec3comment
Combining 11 SET CNOTATION = EXPLICIT SET DROPBLNKLINE = ON DEFINE FILE EMPDATA CNTIT/I1 WITH PIN = 1; END TABLE FILE EMPDATA PRINT SUM.CNTIT WITHIN AREA NOPRINT COMPUTE CTR/I3 = IF AREA EQ LAST AREA THEN CTR + 1 ELSE 1; NOPRINT COMPUTE ALLEM1/A63V = IF CTR EQ 1 THEN PIN ELSE IF CTR LE 7 THEN ALLEM1 | ' ' | PIN ELSE ALLEM1; AS '' OVER COMPUTE ALLEM2/A63V= … COMPUTE FLAG/A1 = IF C2 EQ C1 THEN 'Y' ELSE 'N'; NOPRINT BY AREA NOPRINT SUBHEAD "Employees for Area <AREA " WHERE TOTAL FLAG EQ 'Y' END
Employees for AreaCENTRAL Employees for AreaCORPORATE Employees for AreaNORTH EASTERN Employees for AreaSOUTH EASTERN Employees for AreaWESTERN Combining 12
Averages Customer Asked: Does FOCUS give me a weighted average, or a non-weighted average? Our Answer: Actually Both Types of averages Weighted (some values participate more than others) Non-weighted (all values participate equally) 13
Averages Example Using ACROSS TABLE FILE EMPDATA SUM CNT.SALARY NOPRINT SALARY NOPRINT COMPUTE AVE1/D8.2M = SALARY/CNT.SALARY ; AS '' ACROSS BLANK NOPRINT ACROSS AREA BY TYPDEP/R ROWS 1 AS 'ADMIN' OVER 2 AS SLS/MARKT' OVER 3 AS 'PROGRAM' OVER 4 AS 'PROF SRVCS' ON BLANK SUMMARIZE AS 'weighted ' ON AREA SUBTOTAL AVE. AS 'average' END 14
Averages AREA CENTRAL CORPORATE NORTH EASTERN SOUTH EASTERN ADMIN $32, $56, $80, SLS/MARKT $68, $51, $44, $56, PROGRAM $45, $49, PROF SRVCS.. $40, $49, WESTERN average $31, $50, $46, $50, $54, $53, $42, $45, $45, $47, $45, $46,
16 Dates, Times, and what you can do with them
Dates Types of Dates Legacy format (A,I, Z, P format) Not really a date, but a number or character string which is INTERPRETED as such I8YYMD, P6MDY, etc. Smart Date format Stored as an 'offset' of days, months or year from a base date Can change output format by a re-definition Date-Time format Stored as an offset from a base date Can go down to micro-seconds (precision controls length) All need UWS to manipulate components 17
Dates : Legacy Dates USAGE contains Y (or YY), M, and D after format/length 2 places per letter (I8YYMD – good, I6YYMD – bad) A sequence of digits or characters to be interpreted as a date No validation '123456' as 'A6YMD' displays '12/34/56' (delimiter always '/') FORMAT date components are like EDIT options – only affect display Only 'T' (month translate) format component even looks at data - Translates month to 3 character abbreviation As an ACTUAL, can convert directly to a 'smart date' USAGE Sorted as 'native format' value For example, I6MDY displays all 'January' values first Pre 'Y2K', where the century digits were 'assumed' to be '19' Alpha, packed or zoned – saved on disk storage 18
Dates : Smart Dates USAGE contains ONLY 'date' indicators, no length or data type Internally stored as an offset from the 'base date' January 1, 1901 was day 1 May omit day, or month and day ALWAYS a valid date Format controls display component order Can be changed at will - YYMD can be changed to MDYY Always sorted chronologically (offset sequence) Century implicit in offset (DEFCENT and USERTHRESH) Delimited can be '/' (default), '.' (Y.M), '-' (Y-M), ' ' (YBM), or eliminated (Y|M) May use Q (quarter), JUL (Julian format), or W (day of week) Can translate M with 'T', 't', 'TR' or 'tr'; W with 'R' or 'r' 19
Dates : Date – Time Dates USAGE begins with 'H' (indicates 'Hour' format) Stored as offset, including DATE and TIME Time can be to milliseconds or microseconds Storage depends of precision (8, 10 or 12 bytes) Milliseconds = 8 bytes, Microseconds = 10 bytes Multitude of EDIT options Leading zero suppression/omission AM/PM Upper/lower case 24 hour display Comma or blank separation Comparable to SQL date-time formats UWS begin with 'H' (HADD, HDIFF, etc.) 20
Dates: Useful SETs ALLOWCVTERR – controls display of invalid date conversion OFFgenerates a diagnostic ONdisplays invalid date DTSTRICT – enforces validity of date-time inputs ONreturn 0 if invalid OFFonly check range of values WEEKFIRST – (1 – 7) specifies first day of the week (1=Sunday, 7=Saturday) or (ISO1 – ISO7 : 1 st week with 4 or more days) BUSDAYS – string indicating working days (i.e. _MTWTF_) HDAY – part of the name of a holiday file (HDAYxxxx) Dates in YYMD format DATEDISPLAY – display the base date as 12/31/1900 or ' ' (OFF) DEFCENT/YRTHRESH – set first year of 100 year range (19/00) DATEFORMAT – default order of date components (MDY) 21
Dates: Useful Functions DT() used to set a date-time field to a value Required for COMPUTE/DEFINE and WHERE Not needed for IF conditions FPRINT(infield, 'usageformat', outfield) Converts ANY format (including date and date-time) to alpha Replaces FTOA and PTOA HDATE(value,'YYMD'|outfield) Convert a date-time to date format HDIFF(end_value, start_value,'component',outfield) Find the number of units between 2 date-times HGETC(length,outfield) Get the current date-time 22
Dates: Useful Functions HINPUT(in_length,'input_string', length,outfield) Convert an alpha string to a date-time value HMASK(source,'component_string', input, length,outfield) Move multiple date-time components to a target date-time HNAME/HPART(value,'component', outfield) Retrieve a date-time component in alpha/numeric format DATECVT(date,'infmt,'outfmt') Convert a date/legacy format to date/legacy format DATEDIF(from_date, to_date,'unit') Finding the difference between 2 dates DATMOV(date,'move_point') Move a date to a significant point 23
Dates: Useful Functions DATETRAN(indate,'(intype)','(fmt_opts)','lang',outlen,output) Format dates in international formats AYM/AYMD(indate,increment,outfield) Add months or days to a legacy date CHGDAT('infmt','outfmt', legacy_date,outfield) Change the display of a legacy date DOWK/DOWKL(indate,outfield) Find the day of the week GREGDT/JULDAT(indate,outfield) Convert between Gregorian and Julian format 24
Dates and Dialogue Manager Dialogue Manager only knows ALPHA strings No format allowed Converts 'numeric' strings to numeric when used Routines expecting non-alpha format (date or date-time) Pass values in as ALPHA, convert in the call to the routine Routines produce non-alpha formats Convert result BEORE passing back to D.M. BAD example: -SET &FRDT = ; -SET &TODT = ; -SET &DIFF = DATEDIF(&FRDT, &TODT,'M'); -TYPE FROM &FRDT TO &TODT IS &DIFF MTHS FROM TO IS 328 MTHS 25
Dates and Dialogue Manager BETTER example: -SET &FRDT = ; -SET &TODT = ; -SET &DIFF = DATEDIF( -DATECVT(&FRDT,'I8YYMD','YYMD'), -DATECVT(&TODT,'I8YYMD','YYMD'), - 'M'); -TYPE FROM &FRDT TO &TODT IS &DIFF MTHS FROM TO IS 12 MTHS 26
Dates and Dialogue Manager DEFINE FUNCTION (thanks to Francis Mariani) DEFINE FUNCTION DIFF (FR/I8, TO/I8) FROM/YYMD = DATECVT(FR,'I8YYMD','YYMD'); TO/YYMD = DATECVT(TO,'I8YYMD','YYMD'); IDIFF/I2 = DATEDIF(FROM,TO,'M'); DIFF/A2 = EDIT(IDIFF); END -RUN -SET &FRDT = ; -SET &TODT = ; -SET &DIFF = DIFF(&FRDT, &TODT); -TYPE FROM &FRDT TO &TODT IS &DIFF MTHS FROM TO IS 12 MTHS 27
HDAY Used by DATEDIF, DATEMOV, DATECVT and DATEADD Specifies holidays Example of HDAY file
HDAY Example: SET HDAY=IBI DEFINE FILE CAR HDATE1/HYYMDS = DT( :00:00); HDATE2/HYYMDS = DT( :00:00); DATE1/YYMD = ' '; DATE2/YYMD = ' '; DAYS/I5 = DATEDIF(DATE1,DATE2,'D'); WDAYS/I5 = DATEDIF(DATE1,DATE2,'WD'); BDAYS/I5 = DATEDIF(DATE1,DATE2,'BD'); END TABLE FILE CAR PRINT DAYS WDAYS BDAYS HDAYS WHERE COUNTRY EQ 'ENGLAND' END DAYS WDAYS BDAYS
Tips from Focal Point posts Parameter Date Print By Warren Hinchliffe, Link Market Services Parameter Date Print Truncating Text in the Heading of a PDF Document By Warren Hinchliffe, Link Market Services Truncating Text in the Heading of a PDF Document Simplifying the use of Date functions in Dialogue Manager By Francis Mariani Simplifying the use of Date functions in Dialogue Manager Open Drilldown in a New Tab By Marilyn Patchen Beyer, Minnesota Department of Education Open Drilldown in a New Tab Dashboard HTML Page, Output Block, Multiple Selections - how to do?, By Todd Wallace, Milacron llc Dashboard HTML Page, Output Block, Multiple Selections - how to do? Adding a Conditional Join to a Reporting Object, By Todd Wallace, Milacron llc Adding a Conditional Join to a Reporting Object Embedded Images in Excel By Warren Hinchliffe, Link Market Services Embedded Images in Excel For more tips and techniques, check our website 30