You are on page 1of 15

Are you in FOCUS?

Intermediate FOCUS Training

Tennessee Technological University Cookeville, Tennessee

Intermediate FOCUS Syllabus

-Sorting -BY -ACROSS -BY RANK -IN-GROUPS-OF -Totaling Report Rows and Columns -SUBTOTAL and SUB-TOTAL -More on Defines -HOLD Files -Use of Two Verbs -IF and WHERE statements -JOINS

This manual was adapted extensively from a manual initially created by University of Nebraska at Omaha. Development team and editors: Kay Hume, TTU Richard Cashion, TTU 1996 Tennessee Technological University. This manual may be distributed freely without permission provided that this header and notice are retained intact, proper credit is given to the authors and institutions (including University of Nebraska at Omaha), and that the contents are not altered in any way.

D. W. Mattson Computer Center Tennessee Technological University

Sorting TABLE requests can produce reports that are sorted into almost any
order, using the BY and ACROSS in FOCUS. For example, a list of majors can be sorted by major and then alphabetically sorted by name within each major. BY is the most commonly used sort command. The BY command sorts requested records vertically in rows down the report and is called the vertical sort. JOIN CLEAR * JOIN STU_ID IN RTFILE TO KEY IN AAFILE AS J1 DEFINE FILE RTFILE SIDEDIT/A11 = EDIT(STU_ID, 999-99-9999'); END TABLE FILE RTFILE HEADING CENTER STUDENTS BY MAJOR &DATE [STUMAJ] FOOTING CENTER EXAMPLE FOC201-1 USE OF THE BY COMMAND PRINT SIDEDIT AS STUDENT ID BY MAJOR_1 BY STU_NAME IF KEY EQ 96S$* IF RECORDLIMIT EQ 25 END Note the following points: - The first field being sorted is the first field to be printed. This field is known as the sort control field. If two or more sort fields are present, the first field will appear first, the second next, and so on. Since these fields are printed on the BY command, you do not need to put them on the PRINT command. - If there are duplicate or repeating values in the sort fields, they will not be printed. A field is printed only at the beginning of a duplicate group of fields. - The default in sorting is from the lowest to the highest value, from 0 to 9 in numeric and from A to Z in alpha. The order of sorting can be reversed by adding the word HIGHEST after the BY command. - BY or ACROSS fields can be followed by other BY and/or ACROSS fields.

Intermediate FOCUS Training

Version 1.0 April, 1996

The ACROSS statement


The ACROSS phrase is another command used by FOCUS programs to perform sorting. There are 3 main differences between the BY and ACROSS commands. 1. The ACROSS command places the sorted control fields horizontally across the width of the report. 2. The ACROSS command is best used with SUM and COUNT verbs where you would not have many columns to print across a page. 3. There is a maximum limit of 5 ACROSS phrases in each TABLE request. Continuing with our example, here we can use an ACROSS phrase: JOIN CLEAR * JOIN STU_ID IN RTFILE TO KEY IN AAFILE AS J1 TABLE FILE RTFILE HEADING CENTER COUNT BY MAJOR & CLASS &DATE REPORTED &DATE FOOTING CENTER EXAMPLE FOC201-2 USE OF THE ACROSS COMMAND COUNT STU_ID ACROSS CLASS_LEVEL BY MAJOR_1 IF CLASS_LEVEL EQ FR OR SO OR JR OR SR OR UNC IF KEY EQ 96S$* IF RECORDLIMIT EQ 200 END
PAGE 1 COUNT BY MAJOR & CLASS [STUCNT] Primary,Class FR 04/26/96

JR SO SR UNC Primary Major 1 -----------------------------------------------------------------ACCT 5 7 3 17 2 AGBE 22 0 0 1 0 AGSC 38 0 0 0 0 ANRM 50 8 4 0 0 ANS 0 9 6 3 0 ART 60 9 0 1 0 BE 7 9 8 53 0 BIOL 14 1 9 4 0 BMGT 0 0 0 41 0 Example FOC201-2 USE OF THE ACROSS COMMAND

D. W. Mattson Computer Center Tennessee Technological University

SORTING RANKED BY
The RANK command, when used in conjunction with the BY command, ranks the numerical fields in a file by highest or lowest values. For example, in SIS, you can print a report of students ranked by their GPA. Notice that since 2 people have a 0.000 GPA, they are both ranked as rank 15. TABLE FILE RAFILE FOOTING CENTER EXAMPLE FOC201-3 - USE OF THE RANKED BY COMMANDS PRINT STU_ID RANKED BY HIGHEST HIED_GPA IF CAREER_STU EQ U IF RECORDLIMIT EQ 25 END
PAGE RANK ---1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 Cum GPA HiEd ------3.877 3.521 3.500 3.454 3.296 2.919 2.886 2.817 2.788 2.712 2.698 2.660 2.649 2.019 .000 Student Number ------000000001 000000002 000000003 000000005 000000006 000000007 000000008 000000009 000000010 000000011 000000012 000000013 000000014 000000015 000000016 000000017 EXAMPLE 201-E USE OF THE RANKED BY COMMAND

NOTES:

Suppose we only want the top 5 students in the class. You can use the ranked by command with this: RANKED BY TOP 5 HIED_GPA.

Intermediate FOCUS Training

Version 1.0 April, 1996

TABLE FILE RAFILE FOOTING CENTER EXAMPLE FOC201-4 USE OF RANKED BY TOP 5 PRINT STU_ID RANKED BY TOP 5 HIED_GPA IF CAREER_STU EQ U END
Cum GPA HiEd ------3.877 3.521 3.500 3.454 3.296 EXAMPLE Student Number ------000000001 000000002 000000003 000000004 000000005 FOC201-4 USE OF RANKED BY TOP 5

RANK ---1 2 3 4 5

You can use the word LOWEST instead of TOP # or HIGHEST with the RANK command.

IN-GROUPS-OF
The IN-GROUPS-OF phrase allows you to group your records within a range selected by you. You can also select a toplimit for your report. This command is useful where you would want to compare gpas within different majors on campus, for instance. In the example below, the toplimit is 4.0 and the groups are in a cutoff range of 0.5.
JOIN CLEAR * JOIN STU_ID IN RTFILE TO KEY IN RAFILE AS J1 TABLE FILE RTFILE FOOTING CENTER EXAMPLE FOC201-5 - USE OF IN-GROUPS-OF COUNT STU_ID BY MAJOR_1 ACROSS HIED_GPA IN-GROUPS-OF 0.5 TOP 4.0 IF CAREER_STU EQ 'U' IF KEY EQ '95F$*' END

D. W. Mattson Computer Center Tennessee Technological University

PAGE

1.000 1.500 2.000 2.500 3.000 3.500 4.000 Primary Major 1 -------------------------------------------------------------------------------------ACCT 0 0 0 0 22 41 40 37 2 AGPF 0 0 2 0 1 0 1 0 0 AGPV 2 1 3 3 7 15 13 9 0 AGRI 4 2 10 32 68 54 41 13 0 ARED 0 0 1 1 0 3 6 1 0 ARFI 3 0 0 6 13 15 21 6 5 ASED 3 0 1 1 11 41 36 18 13 BBUS 30 12 28 101 258 201 140 63 20 BE 22 16 25 67 111 113 82 42 11 BIOL 10 0 3 10 45 55 76 17 7 BMGT 0 0 0 7 97 66 53 9 0 CE 0 0 0 6 55 106 88 40 7 CHE 1 0 0 5 18 30 54 31 4 EXAMPLE FOC201-5 USE OF IN-GROUPS-OF

1 Cum GPA,HiEd .000 .500

Totaling Report Rows and Columns


It is nice to have column and row totals in certain reports. FOCUS has a mechanism to do this very easily. ROW-TOTAL will add up numeric fields in each row with a column of totals as the last column. COLUMN-TOTAL will add up each column and produce a final row of the totals. Look at example 2 on page 4. Here, we can produce the same report with totals on both the columns and the rows.
JOIN CLEAR * JOIN STU_ID IN RTFILE TO KEY IN AAFILE AS J1 TABLE FILE RTFILE HEADING CENTER COUNT BY MAJOR & CLASS &DATE FOOTING CENTER EXAMPLE FOC201-6 USE OF ROW-TOTAL AND COLUMN-TOTAL COUNT STU_ID ROW-TOTAL AND COLUMN-TOTAL ACROSS CLASS_LEVEL BY MAJOR_1 IF CLASS_LEVEL EQ FR OR SO OR JR OR SR OR UNC IF KEY EQ 96S$* IF RECORDLIMIT EQ 2000 END

Intermediate FOCUS Training

Version 1.0 April, 1996

PAGE 1 COUNT BY MAJOR & CLASS 04/30/96 Primary,Class FR JR SO SR TOTAL Primary Major 1 -----------------------------------------ACCT 0 17 0 28 45 AGPV 3 3 4 3 13 AGRI 10 12 9 20 51 ARED 0 0 1 2 3 ARFI 5 6 6 8 25 BBUS 73 40 86 14 213 BE 77 10 18 7 112 BIOL 7 12 8 28 55 BMGT 0 24 0 49 73 CE 0 25 11 43 79 SPE 2 3 4 15 24 TC 2 2 1 6 11 WFS 7 6 6 13 32 TOTAL 468 431 371 730 2000

EXAMPLE FOC201-6 USE OF ROW-TOTAL AND COLUMN-TOTAL

Exercise 1:

Write a focus that will give row and column totals of students by permanent counties from Tennessee. Write a focus that will sort students by permanent county in Tennessee and name within county.

Exercise 2:

D. W. Mattson Computer Center Tennessee Technological University

Using SUBTOTAL
There are several subtotal commands in FOCUS: SUBTOTAL, SUB-TOTAL, With the above example, you could use these commands to get SUBTOTALS.
SET SQUEEZE=ON JOIN CLEAR * JOIN STU_ID IN RTFILE TO KEY IN AAFILE AS J1 TABLE FILE RTFILE HEADING CENTER COUNT BY DEPT, MAJOR & CLASS &DATE FOOTING CENTER EXAMPLE FOC201-7 USE OF SUBTOTAL COUNT STU_ID ACROSS CLASS_LEVEL BY DEPT SUBTOTAL BY MAJOR_1 IF CLASS_LEVEL EQ FR OR SO OR JR OR SR OR UNC IF KEY EQ 96S$* IF RECORDLIMIT EQ 2000 END
PAGE 1 COUNT BY DEPT MAJOR & CLASS 04/30/96 Primary,Class FR JR SO SR Primary Primary Dept Major 1 ---------------------------------------------ACCT ACCT 0 17 0 28 *TOTAL ACCT 0 17 0 28 ADP RADM 43 0 1 0 *TOTAL ADP 43 0 1 0 AGRI AGPV 3 3 4 3 AGRI 10 12 9 20 *TOTAL AGRI 13 15 13 23 BBUS BBUS 73 40 86 14 *TOTAL BBUS 73 40 86 14 CHEM CHEM 4 6 2 11 PDEN 1 0 0 0 PDHY 2 0 0 0 PHIM 0 1 0 0 PHTH 5 4 5 0 PMED 6 4 5 4 PMT 1 0 1 0 SOC CJ 3 3 4 2 SOC 11 16 14 32 *TOTAL SOC 14 19 18 34 TOTAL 468 431 371 730 EXAMPLE FOC201-7 USE OF SUBTOTAL

or

Intermediate FOCUS Training

Version 1.0 April, 1996

JOIN CLEAR * JOIN STU_ID IN RTFILE TO KEY IN AAFILE AS J1 TABLE FILE RTFILE HEADING CENTER COUNT BY DEPT, MAJOR & CLASS &DATE FOOTING CENTER EXAMPLE FOC201-8 USE OF SUB-TOTAL COUNT STU_ID ACROSS CLASS_LEVEL BY DEPT SUB-TOTAL BY MAJOR_1 IF CLASS_LEVEL EQ FR OR SO OR JR OR SR OR UNC IF KEY EQ 96S$* IF RECORDLIMIT EQ 2000 END

SUB-TOTAL is identical to SUBTOTAL except that it will also subtotal values of the fields at higher sort levels. So, if you said BY RT_COLL BY RT_DEPT SUB-TOTAL BY MAJOR_1 , then subtotals would appear at a change of department and also at the college level. Exercise 3: Write a focus to use SUBTOTAL to sum attempted hours at the major, department and college level. Write the focus above using SUB-TOTAL on department.

Exercise 4:

10

D. W. Mattson Computer Center Tennessee Technological University

More on Defines
A review of the general syntax of the DEFINE command is as follows: DEFINE FILE filename New field/format = expression; END DEFINE can create new fields, create fields that contain literals (like 03M when building an address transaction record), add or do numeric operations on numeric fields and put the result in a define field, edit a field such as STU_ID to become 999-99-9999' with the embedded dashes for printing, perform logical tasks using IF THEN ELSE AND OR statements, decode fields (well see this later), and so forth. The DEFINE CLEAR command cancels any defines that are in previous TABLE requests in the same run. Exercise 5: Write a focexec using a DEFINE to figure out U GPA using quality hours and quality points. Write a focexec using a DEFINE to print state of origin. If state of origin is Tennessee leave it that, but if it is anything else, print XX.

Exercise 6:

Intermediate FOCUS Training

Version 1.0 April, 1996

11

Hold Files and Use of Two Verbs


Occasionally you will compile information from several files. To speed the process, it is better to identify your population, place it in a file and join that file to other areas. For example, you need to find out how many native American students were enrolled in the Fall of 1990 and what their enrollment status was and also get their U GPA.
JOIN STU_ID IN RTFILE TO KEY IN AAFILE AS J1 TABLE FILE RTFILE PRINT STU_NAME RT005 BY STU_ID IF ETHNIC_ORIGIN EQ I IF KEY EQ 90F$* IF RECORDLIMIT EQ 2000 ON TABLE HOLD AS HOLD1 END JOIN STU_ID IN HOLD1 TO KEY IN RAFILE AS J2 DEFINE FILE HOLD1 SIDEDIT/A11 = EDIT(STU_ID, 999-99-9999'); END TABLE FILE HOLD1 FOOTING CENTER EXAMPLE FOC201-9 HOLD FILES AND THE USE OF TWO VERBS COUNT STU_ID BY RT005 PRINT STU_NAME SIDEDIT HIED_GPA BY RT005 IF CAREER EQ U END

This example includes: - creation of a hold file, - adding a new field to a file using a define, - using the FOCUS generated alias to access information, - two verbs in one request - and elimination of records that dont have a RTFILE record with the IF statement. Exercise 7: Write a FOCEXEC to get from the RTFILE students in the major of ACCT in the term 96S. Hold to a file and then join this file to the MMFILE to get their application term. Print a report of their major and application term.

12

D. W. Mattson Computer Center Tennessee Technological University

Use of WHERE statement


WHERE is very similar to the IF statement. Actually the only place you would want to use an IF instead of a WHERE , is the statement IF KEY EQ 96S$* - using IF when checking a KEY field. You will always need to use a WHERE when doing a field-to-field comparison, such as WHERE PIN EQ BIRTH_DT. Here , you are not comparing PIN to a literal such as WHERE PIN EQ 111111' but you are comparing PIN to another field, BIRTH_DT. Exercise 8: Print a list of 25 people whose PIN number is the same as their birthdate. Make the birthdate print out in the form YY/MM/DD.

More about JOIN


The JOIN command allows you to report from two or more related files with a single request. Joining files will return the data from the common records in all the files joined. It allows the user to answer such questions as: Show me all of the registered students by ethnic origin ---RTFILE and AAFILE How many applicants are from each state and each gender within each state ---- MMFILE and AAFILE Provide a class list of all registered students ---- RTFILE, AAFILE, and RCFILE All of this can be done with the use of a single TABLE command. Joined files remain physically separate, but FOCUS treats them as one logical unit for the FOCUS session. As we discussed in the FOC101 class, the JOIN command is used to JOIN two or more files together. To JOIN these files, you must have fields that are in common with both files. The JOIN syntax is: JOIN anyfield IN FILE1 TO key (or first part of key) IN FILE2 AS J1 When two files are joined together, the first file is called the host file and the second is called the cross-referenced file. The host files is ALWAYS the file you gather your population from and is the TABLE FILE.

Intermediate FOCUS Training

Version 1.0 April, 1996

13

The following is a simple join from one file to another: JOIN STU_ID IN RTFILE TO KEY IN AAFILE AS J1 This next join requires a new field to be created. The key in the RCFILE is TERM AND SECTION_ID , and we have those 2 fields in the RTFILE but we need to make them into 1 fields to use in the JOIN command. Also, we use the WITH SECTION_ID to give the newfield we have defined in the RTFILE a parent. This will ensure that even though a person in the RTFILE occurs 1 time, their courses exist more than once in the RTFILE, and this will ensure that ALL of their courses will be joined to the RCFILE. JOIN NEWKEY WITH SECTION_ID IN RTFILE TO KEY IN RCFILE AS J1 DEFINE FILE RTFILE NEWKEY/A14 = TERM|SECTION_ID; END Another kind of join that is required often is the following. Since the SAFILE does not have the term (96S) which is required to JOIN to the RTFILE, we have to include the term ourselves and create a new field called NEWKEY in the DEFINE FILE section. Again the WITH STU_ID in the JOIN statement gives the new fields created (NEWKEY) a field that always occurs in the SAFILE (STU_ID) to latch onto. JOIN NEWKEY WITH STU_ID IN SAFILE TO KEY IN RTFILE AS J1 DEFINE FILE SAFILE NEWKEY/A14 = 96S|STU_ID; END A fourth kind of JOIN is the JOIN used when the cross-referenced file has more than one segment. For example the entire key in the SWFILE in FAM is award year, stu_id, and fund code. Each person can have more than 1 record in the SWFILE. To join to ALL of a persons SWFILE records, the following join could be used: JOIN KEY IN SAFILE TO ALL SUBKEY1_SW IN SWFILE AS J1

Exercise 9:

Write a FOCEXEC using the AAFILE as

14

D. W. Mattson Computer Center Tennessee Technological University

the host file and join the AAFILE to the RAFILE and print some info for both files on a record limit of 25 people. Exercise 10: Write a FOCEXEC to again use the AAFILE as the host file and join to the RTFILE for the term 95F. Write a FOCEXEC and JOIN the RTFILE to the SAFILE for the award year 96' for the term in the RTFILE of 95F on 25 people.

Exercise 11:

Intermediate FOCUS Training

Version 1.0 April, 1996

15

You might also like