Professional Documents
Culture Documents
-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.
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.
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
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.
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
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
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
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:
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
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
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:
11
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
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:
14
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:
15