Host Systems

Getting Organized in Mac OS

Rick Asler

If you work on just one simple project with SAS MAE is emulation to run Mac on some software, it may not matter very much how you systems. It is not the best way to run SAS organize your files. But if you work on a complex software. project or on several projects, your productivity and SAS software requires at least version 7.5 of peace of mind depend on organizing your projects Mac OS. .5 shipped on new computers in effectively. 1994-1995 and can be purchased separately for This paper presents a system for organizing the older computers. A new system version is due in files of SAS projects, taking advantage of the 1996. special features of Mac OS. Then it demonstrates A computer system for running SAS software techniques for automating SAS projects. should also have at least an average-size hard disk and at least 16 megabytes of physical RAM. The is the main application that is always Mac essentials running in Mac OS. It displays disks and files as icons and subdirectories as folders. First, these are some Mac terms and features The is the folder containing the you may need to be aware of to operate SAS , Finder, and other Mac OS files. software under Mac OS. The Trash Is a Finder container where deleted Mac, Mac OS, Mac , or Macin­ files go. You can retrieve them Hyou don't wait too tosh operating system is the distinctive graphical long. operating system of Apple Computer. Mac users An is a small file that refers to another file. usually just call it the System. When you move or rename the original file, Mac A Mac-compatible computer is one that runs updates the alias to maintain the link. Mac OS. Mac-compatible computers are made by SimpleText is the Mac OS (called Apple, Radius, Power Computing, DayStar, Pioneer, TeachText in earlier versions). and others. You can identity Mac-compatible computers by the Mac OS logo. A , Power Macintosh, Quadra, CentriS, Organizing SAS software or PowerBook is a Mac-compatible computer made by Apple Computer. The default SAS software installation includes PowerPC is the central processor of choice for both PowerPC and 68000 versions of binary code. Mac-compatible computers running SAS software. To save hard disk space, install only the one set of 68040 and 68030 are central processors from the binaries for your computer's central processor. 68000 family, used in older Mac-compatible After you install SAS software on your Mac­ computer models. They're slower, but fast enough compatible computer, there are new files in various for most SAS applications. locations on the hard disk. To work with SAS A floating-point unit (FPU) is a good thing to software, you need to be able to find the following have for running SAS software. PowerPCs and icons in the Finder: most 68040s include an FPU. Some computers with a 68030 have an FPU as a separate processor SAS preferences folder. This is the ·SAS· folder (a math co-processor). in the "Preferences" folder in your system folder. You need a CD-ROM drive to the CD that SAS root folder. This is the folder, usually in the you install SAS software from. You might borrow root of your hard disk, that contains the an external drive, because SAS software installation SAS application. The "SAS local" alias in the SAS only takes minutes. preferences folder pOints to this folder. F-keys are the dedicated function keys found on many Mac keyboards. Some users find them SAS application. This is the ·SAS" icon in the SAS indispensable for running SAS software in Mac. root folder. Some Macintosh models, particularly the SE/30, Classic II, Color Classic, and PowerBooks, have Configuration file. This is the with the built-in monitor screens that are too small to run name beginning with "config.sas" in the SAS root some interactive parts of SAS software comfortably. folder.

353 Host Systems

Improving your setup can change the minimum and preferred memory After the installation, there are several things you size for the SAS System. Reduce the minimum can do in the Finder to make SAS software easier to memory size if you must run the SAS System with work with. less memory - but then, don't a lot of windows or do a lot of things at once in the SAS 1. Delete the Option Editor application. Even if session. Adjust the preferred memory size to give you like its look and feel (and it's not a crowd· the SAS System most of the memory that is left pleaser), it's not worth the amount of RAM it takes over after you set aside space for any other up when you run it. applications you run at the same time. If you have plenty of physical RAM, give the SAS System about 2. Make an alias for the SAS preferences folder. 21 megabytes. Call it ·SAS preferences folder" and move it to the In the Memory control panel, you can set up SAS root folder. This gives you an easy way to get virtual memory. This does not give you any from the SAS root folder to the SAS preferences memory for the SAS System, but can allow you to folder. run other applications at the same time, with some 3. Move the configuration file to the SAS compromises in speed. In the Monitors control panel, set color depth to preferences folder. Just drag it onto your new ·SAS preferences folder" icon. no more than 8 bits - less if you have limited RAM. 4. Create a SAS projects folder. Make a new folder called ·Projects" in the SAS root folder. Use If you haven't already done so, make an alias of this folder for aliases of project folders. your hard disk and put it in the Apple Menu Items folder in the System Folder. In the Apple Menu Configuration file Options control panel, tum on the submenus option. You use the configuration file to tell the SAS This puts your hard disk and its folders on the Apple System what options to start up with. Unlike in all menu, so you can open files and folders on your other operating systems, SAS software for Mac hard disk, such as SAS project files, directly from doesn't offer a convenient way to tell it what con· the Apple menu. figuration file to use. Instead, it always looks for a particular file name (such as "config.sas61 0j first in the SAS preferences folder, and second in the SAS Organizing projects root folder. Options in the SAS root folder override options in the SAS preferences folder. The simplest way to keep track of projects is to In the first configuration file - in the SAS prefer· put each project in its own directory, or folder. Mac ences folder - set options for a display as makes it easier to do that. I prefer to put the session that is not associated with any particular project folders in the root directory of the disk, but project. In most cases, you won't need to change you can put them wherever is convenient for you. the original installed configuration file. It is a good idea to keep the project folders Use the second configuration file, in the SAS separate from the SAS root folder. That makes root folder, for options that are specific to a particu· backups, updates, and any sort of file management lar project or SAS session. Use SimpleText to cre· easier to do. ate the second configuration file, so that when you Within the project folder, you should usually have open it in the Finder, you can edit it in SimpleText. several more folders: If you use just one such configuration file, you • A folder for each SAS library you use in the would use these steps to launch the SAS System: project. Use the librel as the folder name. 1. Open the configuration file (in SimpleText), edit it • A folder for input data files. These files could be as needed, and save it. Quit SimpleText. aliases of files stored elsewhere on a network. 2. Open the SAS application icon. • A folder for output data files, if appropriate. Usually, it's more convenient to keep a separate • A folder for print files, appropriate. configuration file for each set of system options you if use. I'll describe that later. • Possibly a folder or folders for SAS programs, if you have a lot of them. Memory management In the Get Info box for the SAS application The project folder should also include an initial· (accessible from the File menu in the Finder), you ization file and configuration files.

354 Host Systems

In the Finder, your project folder might look like options in the batch configuration file. The SYSIN this: option names the SAS program file, which should be the file "sysin' in the project folder. The LOG and PRINT options name the project's log and standard print files. The extra lines might be: -- -nodms El S LJ LJ -sysin 'Real:My Project:sysin' ma.x.c.sas B.tch OLDDATA NE'w'OATA -log 'Real:My Project:log' LJ LJ LJ -print 'Real:My Project:standard print' OUTDATA MAIN Progrorns Although it isn't strictly necessary, I prefer to set up a separate configuration file for each interactive SAS application I use in a project. This makes it easy to run the different interactive applications The project Initialization file from the Rnder. To launch the SAS system with a project An initialization file is a SAS program that runs at configuration file, follow these steps: the beginning of a SAS session. Typically, the initialization file includes statements to declare files 1. Make an alias to or copy of the configuration file used in the project: a LlBNAME statement for every in the SAS root directory. Name the copy or alias SAS data library and a statement for with the standard configuration file name (such as every text file. If you move a project from a ·config.sas61 0"). mainframe environment to Mac, the initialization file replaces the command file or JCL you may have 2. Make an alias to the program file you're running used to declare files. Because all the project's files (in batch processing). Put the alias in the project are contained in the project directories, either folder and call it "sysin." physically or as aliases, every physical file name in the LlBNAME and FILENAME statements will begin 3. Open the SAS application icon. with the project folder. The initialization file typically also includes a This process can be automated by scripting, as TITLE statement and may include other SAS state­ described shortly. ments. The initialization file for a project might look like this: Shared files It usually happens that a project uses files that TITLE1 'My Project'; do not originally belong to the project. One common FILENAME PRO 'Real:My Project:'; situation is that the input data files for a project are created somewhere else. FILENAME OLDDATA 'Real:My Project:OLDDATA:'; Whether the files are on the same computer, on FILENAME NEWDATA 'Real:My Project:NEWDATA:'; a file server, or on another computer on a network, FILENAME OUTDATA 'Real:My Project:OUTDATA:'; you can create aliases for those files and store the UBNAME MAIN 'Real:My ProjectMAIN:'; aliases in the project folder. It's also common for a standard set of programs Call the initialization file "autoexec.sas· and store to be used in several projects. Put those programs it in the project folder. in their own folder, and put an alias of that folder in each project. The project configuration file Using aliases in this way makes file manage­ Most simple projects should have two configura­ ment easy. You can make most file changes in the tion files: one for display manager sessions and Finder. It is rarely necessary to modify SAS another for batch sessions. Some projects may programs to reflect file changes. need more than two configuration files. These files contain any special system options for the project. Create these files even if initially you have no Backup copies special system options for the project. I prefer to call them "Interactive" and "Batch." Backup copies of the files of a small project are The only difference between the two is the as simple as dragging the project folder onto a NODMS, SYSIN, and perhaps LOG and PRINT

355 Host Systems

floppy disk. Somewhat larger projects may be copied onto a few flopp~ disks. . o The Tell statements directs commands to a For a large project, It may be more effective to specific application. File-management tasks are use a backup utility program. Tell it to make or handled by the Finder. maintain a backup of the project folder. On the o The logical-not character (.... ) at the end of a line other hand, for some projects, you may only need to indicates that the statement is continued on the next keep backup copies of the program files. line.

o Moving a file to the trash is the familiar Mac way of Project scripting deleting files. In a script, the Delete command would do the same thing. If you decide after you AppleScript is the little-known Mac command run the script that you really didn't want to delete language. You can use AppleScript to automate one of those files, you can usually retrieve it from commands of the Finder and other Mac applica­ the trash. tions. Currently, the SAS System has a very limited scripting interface, so for a SAS project, you'll use Script applications the scriptable commands of the Finder. Creating a script application is a simple proces~. Launch the Script Editor, type the script, and save it A single·purpose script as a script application. Then, to run the script, just You could a script to launch the SAS open the script icon in the Finder. System with a project's configuration file for a partic­ ular project, possibly running a particular program The Batch Box application file. The script creates an alias for the configuration Script applications can also be designed to have file in the SAS root directory and another alias file icons dragged onto them in the Finder. Such "sysin" for the program file. scripts have an open handler that executes when Such a script might look like this: the script opens a file. The script below, called Batch Box, is d~sign~d on run to run SAS programs in batch mode. ThiS SCript tell appHcation 'Finder" consists mainly of the open handler, which rea~ to if exists file 'Real:SAS:config.sas610' then SAS program files that are dragged onto the Icon, move file 'Real:SAS:config.sas610' to container 'Trash' and the subroutine Run_batch, which creates the end if configuration and ·sysin" aliases and launches the if exists file 'Real:My Project:sysin' then SAS System. The script depends on the exist~nce move file 'Real:My Project:sysin' to container 'Trash' of the project configuration file ·Batch,· as described end if previously. make new aHas file at folder 'Real:SAS' to file ... 'ReaI:My Project:Batch' with properties ... Batch Box (name:'config.sas61 a'} make new aHas file at folder 'Real:My Project' to file ., Runs SAS program in batch mode using configuration file "Batch.' 'Real:My Project:update.sas' with properties ... ©1995 Rick Aster. (name:'sysin'} Breakfast Communications Corporation, end tell P. O. Box 176, Paoli, PA 19301-0176. tell application 'ReaI:SAS:SAS' launch end tell property sasroot: 'Real:SAS 6.10:' end run property confiQ..name : 'config.sas610' property program_max: 28800 - time Omit, in seconds AppleScript (in the u.s. English dialect shown here) is potentially more English-like than most on run command languages, so you may be able to read set aJile to choose file of type 'TEXT' and understand the script above without any open {aJile} specific knowledge of AppleScript syntax. Here are end run some things to look for:

o This script consists entirely of a run handler, a set on open names of commands that are executed when the script is tell application 'Finder' run. if process 'SAS' exists then error 'SAS application is already ruming.'

356 Host Systems

retum following points: end if end teU • The With Timeout statement overrides AppleScript's default time limit of 60 seconds repeat with file_name in names for a command to execute. run_batch from (file_name as string) • The Enclosing_folder subroutine does some end repeat simple character string processing to find the end open folder that contains a file or folder. on ru"-batch from file_name • The phrase ·of me" distinguishes a subroutine set confi9-folder to enclosin9-folder for file_name from a command. tell application 'Finder' if not (exists file (conli9-lolder & 'Batch')) then • The Repeat With ... In statement acts tihe set confi9-lolder to enclosin9-lolder of me for confi9-folder same as the DO OVER statement of the SAS if not (exists file (configJolder & 'Batch')) then retum data step. end if il exists file (sasroot & confi9-name) then.., Running Batch Box move file (sasroot & confi9-name) to container 'Trash' The Batch Box application is most useful if exists file (configJolder & 'sysin') then.., when its icon (or an alias, if you prefer) move file (configJolder & 'sysin') to container 'Trash' appears on the desktop, as shown here. The make new alias file at folder sasroot to file .., downward-pointing arrow on the script appli­ (confi9-lolder & 'Batch') with properties {name:confi9-namej cation icon indicates tihat you can drop file make new alias file at folder config.JoIder to tile .., icons onto it. Iile_name with properties {name:'sysin') First, you need to modify the properties at end tell the beginning of the script to reflect your tell application 'SAS' actual SAS root folder and release with timeout of program_max seconds number. You may also want to adjust launch the time limit. end timeout Then, drag one or more SAS end tell program files onto the Batch Box icon. end run_batch Batch Box tells the SAS System to run the programs. If you run more than one on enclosingJolder lor name program, each program is run in a set name_string to name as string separate SAS session. set ito 0 The SAS programs run in alphabet· set colonjndex to Q ical order. To run a set of programs in a set len to count characters of name_string particular order, rename the program repeat with i from 1 to len files (or their aliases) so that they start if (character i of name_string) is ':' then with sequence numbers. set colonJndex to colonjndex & PI end if Script application from script end repeat You can also use a script to run a script - No colon: return text of argument application such as Batch Box. This script is an if (count of colonjndex) =0 then retum name_string example of that: - Normally: truncate after last colon set truncation-point to last item of colonJndex property batchJist : {'Real:My Project:Programs:l.first.sas', .., - Folder: truncate after next to last colon 'Real:My ProjectPrograms:2.second.sas') if (count of colonjndex) > 1 and Oast item of colonjndex) = len then set truncation-POint to item ·2 01 colonjndex on run end if tell appDcation 'Batch Box" return (characters 1 thru truncation-point of name_string) as string launch end enclosin9-folder with timeout of 54000 seconds open batchJist This script, while still fairly simple as scripts go, end timeout may not make easy reading for the AppleScript endteU novice. If you want to make the attempt, note tihe end run

357 Host Systems

More scripting also mean that custom user interfaces for SAS applications could be created using external While it isn't possible for me to describe all of the software development tools. It might even be possibilities of scripting, I'd like to mention a few possible to use the SAS System as a database points that may be of special interest to SAS server for other applications. software users. Other SCripting systems Multiple applications Other scripting languages are available for Mac. A script can address several applications in Also, it's possible to access the same application sequence. As one example, a script could run a commands from a general-purpose programming SAS program to create a SAS print file, then open language such as C. Microsoft Word and run a Word macro to reformat and print the file.

Recording Getting a project organized makes it possible to A single-purpose script can be created with the do the same computer work with less effort. A well­ recording feature of Script Editor. The process is organized project also lends itself more easily to similar to recording a macro, but only scriptable automation, which further reduces the amount of actions can be recorded. work required to achieve a result. The purpose of all this is to save time, to shift Job scheduling some work from humans to machines. At the same A script application can be designed to stay time, the consistency of an organized, automated open, check the time periodically, and launch script project tends to reduce errors. Features of the Mac applications or other applications according to a make it easy to organize the files of a schedule. For example, you could schedule SAS project in a way that appeals to a person's intuition. programs to run overnight or have a program run as Scripting makes it possible to automate most soon as a file becomes available. routine tasks. With these and other features, Mac OS may possibly be the easiest operating system in Project management which to organize complicated SAS software projects. You can use scripts to automate such tasks as creating new SAS projects and making backup copies of projects.

SAS statements Reading You can execute AppleScript commands from Apple Computer, Inc., AppleScript Language Guide: inside a SAS session using the X statement, the English Dialect. Addison-Wesley. SYSTEM routine, and other SAS System elements that execute operating system commands. Here is Rhena Seidman and Rick Aster, "How to Automate Table a dramatic example of the X statement with an Typesetting of SAS Output in Microsoft Word," in AppleScript command: Reporting From the Field: SAS Software Experts Present Real-World Report-Writing Applications. SAS Institute Inc. X 'tell application ·SAS' to quit';

Executing AppleScript commands from within a SAS session is currently somewhat limited, but with experimentation you should be able to launch Contact another application in the middle of a SAS Rick Aster, Breakfast Communications Corporation, P. O. Box 176, Paoli. PA 19301-0176. application. Of course, this capability has practical value only if you manage memory to allow some memory left over after the SAS System is loaded.

Scriptable SAS System SAS Institute has promised that a later release of the SAS System for Mac will be scriptable. That Apple and Macintosh are registered trademarks of Apple means that various objects within a SAS session Computer, Inc. SAS is a registered trademark of SAS will be able to be acted upon from a script. It may Institute Inc.

358