Simple Sort in FOCUS There are a number of ways that you can control the sort order in your report. The first is the BY clause: 00001 TABLE FILE AAFILE 00002 PRINT 00003 AA002 as ID_NUMBER 00004 AA003 00005 BY AA003 NOPRINT 00006 END This will sort the report by NAME. NOPRINT is used in line 5 because the NAME field has already been specified in line 4. Without the NOPRINT statement, the report would print NAME in the first column, since that is the sort field. It would also display NAME in the third column because we have specified that we want to see that field (in line 4). Reverse Order Sort By default, the sort is from low to high values. That is, records with low values in the specified sort field will be listed first. You can change this to sort in the reverse order, from high to low, by using the HIGHEST option: 00001 TABLE FILE AAFILE 00002 PRINT AA006 00003 AA002 00004 00005 BY HIGHEST AA006 NOPRINT 00006 END This report will list the names in reverse order with those names that begin with letters from the end of the alphabet being printed first. Defining Your Own Sort Order You can also use the BY...ROWS phrase to define your own sort order. For example: 00001 TABLE FILE STERM 00002 PRINT 00003 ID_NUMBER 00004 NAME 00005 BY COLLEGE1 ROWS BUSINESS OVER SCAT OVER 'ARTS & SCIENCES' 00006 OVER MEDICINE OVER EDUCATION 00007 END The order of the sort in the above example will follow the order of the COLLEGE1 values as they have been specified in the OVER portion of the command (in lines 5 and 6). In the example, Business records will print first followed by SCAT, Arts & Sciences, Medicine, and Education. Note that records with values that are not specified will not be included in the report. Thus, Music records will be ignored. Also note that a single quote is needed when the value contains a space as in Arts & Sciences. Displaying the Highest n Records You can also use this technique to display only the highest 10 or lowest 20 records based on the specified sort field value. For example: 00001 TABLE FILE MARIST 00002 PRINT 00003 STU_ID 00004 NAME 00005 BY HIGHEST 100 TOTAL_DUE 00006 END This will list the 100 records with the highest values in the numeric field, TOTAL_DUE. This will only work with numeric fields. Group Data You can also group data based on numeric fields. For example: 00001 TABLE FILE STERM 00002 PRINT 00003 ID_NUMBER 00004 NAME 00005 BY TOTAL_DUE IN-GROUPS-OF 1000 00006 END The report would look something like: TOTAL_DUE --------1000 2000 ... etc ... ID_NUMBER --------123456789 222222222 221122112 333333331 NAME ------------------SMITH, GREG JONES, GREG JONES, TOM SKY, LUKE Nested Sorts You can have "nested" sorts. For example, to sort a listing by college and then by department within college and then by name with in department, the following would suffice: 00001 00002 00003 00004 00005 00006 00007 TABLE FILE MARIST PRINT STU_ID NAME BY COLLEGE1 PAGE-BREAK BY DEPARTMENT LINE-BREAK BY NAME NOPRINT 00008 END List the top-most sort field first. In this case, we want the list to be sorted by COLLEGE1 first. PAGE-BREAK will create a new page each time the value of COLLEGE1 changes in the list. Within each college, DEPARTMENT will sort the list with a blank line between the sort groups. Finally, the report will list the students in alphabetic order within each department.