SAS for Linux
SAS is a general purpose, statistical package and high level data management programming language from the SAS Institute in Cary, North Carolina. SAS is widely used in academia and industry.
SAS for Linux, Version 9.4 (TS1M2) is available on compute server charisma. A Sociology Linux account is required for use.
1. Modes of Access
Web Access via SAS Studio - a newer approach allowing use of SAS through a web browser
Terminal Access via SSH - from terminal mode SAS can be launched as a graphical application (analogous to SAS for Windows) or run in batch mode
2. Web Access via SAS Studio
SAS Studio, of recent origin in the SAS product line, provides a web-based method of SAS delivery, of particular importance to the growing legion of OS X users for whom SAS is not readily available. Terminal access methods are powerful, but resisted by those wanting fewer connectivity issues.
A few particulars about SAS Studio for Duke Sociology:
- SAS Studio runs on charisma, the same Linux host used for terminal access.
- Access requires multifactor authentication - first with Duke NetID credentials, then by login to charisma with Sociology credentials.
- This service is restricted to Sociology affiliates.
- Server connections and data transfers are encrypted.
- Best results require your web browser to be a current version of Chrome, Firefox, Safari or Internet Explorer
2.1. Connecting to SAS Studio
Open your web browser to https://sasstudio.soc.duke.edu
Complete the standard Duke SIGN IN page with your NetID credentials. A self-signed certificate is currently in use. Accept this certificate. Chrome requires acceptance each time.
The SAS Studio Sign-In screen appears. Enter your Sociology userid and password.
- Sign-in proceeds and an opening screen similar to below appears.
2.2. Mastering SAS Studio
Authoritative guides for SAS Studio are found on the SAS Support page.
The most immediately relevant are the PDF Getting Started and User's guides.
- The web interface is divided into navigation panes on the left and a tabbed work area on the right for data, code, logs and results.
- Two general operational perspectives are available.
The SAS Programmer perspective [the default] is appropriate for a user wishing to write and run SAS code.
The Visual Programmer perspective is appropriate for a user putting together a series of program and data building blocks to perform some task. These typically pre-exist. SAS programming in an academic research setting usually is not structured in this way unless or until a high level of complexity and organization is first achieved.
- SAS Studio incorporates the powerful Output Delivery System and allows for seamless result downloads in HTML, PDF and RTF formats.
3. Terminal Access via SSH
3.1. SSH Access Requirements
Windows users require:
PC X-Window server software for X11 services - Use X-Win32, freely distributed by OIT. Make sure you are upgraded to Version 2014 or newer.
An SSH client for connectivity - We recommend F-Secure SSH Client, freely distributed by OIT. When installing this (or any other SSH product), configure tunnelling of X11 connections.
Prior to opening a SAS session:
- Load X-Win32. This makes X11 services available on your PC.
- Load F-Secure and open a termnal session to charisma.soc.duke.edu.
Mac users require:
Availability of X11 services - X11 is not included in recent versions of OS X, but is available as a free package download from the XQuartz download site. Install the recommended XQuartz package from the "Quick Download" link to provide X11 functionality.
An SSH client for connectivity - No user installation is required. SSH is native to the OS X platform.
Prior to opening a SAS session:
Open a terminal window and start an SSH session to charisma as below. The -X option ensures proper operation of SAS in graphical mode. The login specification consists of your Sociology userid, followed by @ and the fully-qualified hostname for charisma.
$ ssh -X abc12@charisma.soc.duke.edu
3.2. Invoking SAS and Submitting Programs
Once a tunnelled SSH connection to charisma is established, SAS may be run in interactive or batch mode. When learning SAS, interactive mode is preferrable. Experienced SAS users often come to prefer batch mode, especially for complex programs that require hours or days to complete.
3.3. Interactive Mode SAS
To invoke interactive SAS, change to the directory in which you wish to work and type:
sas &
Placement of the ampersand (&) after the command returns the terminal command prompt, leaving the command line available for other activity.
The SAS splash screen appears momentarily followed by seven windows:
Toolbox:Explorer - with icons for commonly performed actions
Explorer - with links to various parts of the SAS environment
Results - with structured organization of portions of SAS outputs [initially hidden behind Explorer]
Program Editor - where SAS code is written and submitted
Log - where the results of executed SAS code are displayed
Output - where the results of SAS procedures are displayed [initially hidden behind Log & Program Editor]
Session Management - options for SAS session management [initially minimized]
The Linux SAS program editor is quite different from the Windows SAS editor. It should be reconfigured to behave like the Windows editor, as described in Giving the SAS Program Editor Under Linux a Windows Look and Feel.
Keyboard Behavior: When access is through X-Win32 and an SSH client under Windows, make sure that the NumLock key is toggled off. When enabled the Backspace and Delete keys do not work in the SAS Program Editor.
Reviewing the SAS Log: Always examine your SAS log carefully for color-coded notes (in blue), warnings (in green) and error messages (in red) that allow you to verify correct program execution or diagnose problems in syntax or logic.
3.4. Handling Interactive Mode Output
Interactive Linux SAS produces two output formats.
Standard text listings appearing in the Log and Output windows
HTML formatted Log and Output listings that appear in remote web browser windows.
Curiously HTML output only displays when you have previously opened the firefox browser on charisma. Otherwise it is generated, but doesn't display. Notably an open browser is also a prerequisite for accessing features through SAS Help menus.
If HTML output matters not to you, suppress it from any window by selecting Tools > Options > Preferences > Results Tab. Deselect Create HTML. The Create Listing option remains in effect. Click OK.
Printing log and output listings can be bewilderingly complex in SAS. For the sake of simplicity, a reasonable printing template is preconfigured. You just need to decide your preferred network printer.
From a Log or Output window select File > Print to open the print dialog window.
A default PostScript Duplex driver is used to provide double-sided printing
- Linesize is 110 characters
- Pagesize is 71 lines
- An 8 point monospace font is default
- All margins are 0.75 inches
Click Properties..., then the Destination Tab in the resulting window. Note the initial defaults.
Device type Disk
Destination sasprt.ps
These settings result in a PostScript file called sasprt.ps being written to the directory from which you loaded SAS. Some may want this type of output, but the presumption here is the need for hard copy.
Select the Device type dropdown pointer and change Disk to Printer. As shown below, output is now directed to the default network printer - copy2. Select a different network printer by typing an alternate printer name - lab or copy3 - into the Destination field.
Click OK in the Printer Properties window. Click OK in the Print... window. Output should be directed to the default or specified printer.
If your SAS Display Manager settings set to be permanent (as done with Tools > Options > Preferences... > DMS tab > Save Settings on Exit), any print modifications become permanent. The File > Print > OK sequence will consistently print to the same printer.
3.5. Batch Mode SAS
Batch mode is most appropriate for long or numerous production jobs where work needs to be pipelined through as efficiently as possible by an experienced SAS programmer.
3.5.1. Job Preparation
Batch mode SAS programs are easily maintained with a text editor such as vi, emacs or pico (see Linux Editing) or your preferred editor under Windows. By convention, .sas is the file name extension for SAS programs. Assume, for example, a program called recodes.sas.
3.5.2. Job Submission
To submit the above program, type at the command line prompt:
sas recodes.sas &
Inclusion of the ampersand (&) returns the command line prompt, while SAS executes the program in the background, allowing you to do other work. When the job completes, SAS writes text file log and listing outputs to the current directory and reports job completion in the terminal window. Output files are named in tandum with the program file, so in this example, the result files are named recodes.log and recodes.lst.
Running multiple batch jobs at once often further improves efficiency.
3.5.3. Viewing Output
Conveniently view batch results with the less paging command:
less recodes.log
The less utility supports quick output paging and scanning for things of interest. Navigation involves simple keystrokes and string searches:
spacebar - to scroll to the next screen
b - to scroll back a screen
q - to quit
/pattern - to search forward for an instance of pattern [when found instances are displayed in reverse video]
/ - to repeat forward search
?pattern - to search backward for an instance of pattern
? - to repeat backward search
3.5.4. Printing Output
SAS batch output is printed from the command line. Assuming the example SAS job recodes.sas produces log and output files named recodes.log and recodes.lst, both are printed in duplex to the default Linux printer (copy2) with the enscript command:
enscript -G -DDuplex:true -fCourier8 recodes.log recodes.lst
The options control the page header (-G), toggle on duplexing (-DDuplex:true) and set font size (-fCourier8). These are recommended as optimal settings. Omit the duplex option if you want single-sided ouput.
Adding a printer specification sends to the alternate lab printer:
enscript -Plab -G -DDuplex:true -fCourier8 recodes.log recodes.lst
For more in-depth discussions see Linux Printing and Handling SAS Output Under Linux.
3.5.5. Cross Platform Access
Linux SAS programs and outputs saved under the user lanhome network directory are directly available to local Windows and OS X PCs when network mapping is in effect.
4. Online Help Resources
SAS provides documentation through searchable, online tools and through detailed manuals available as downloadable PDF files. The table below organizes some of the more useful documentation links for the 9.4 release. The online documentation is quickly searched and provides focused information. The PDFs are more detailed and broader in scope. SAS documentation applies to Windows and Linux unless otherwise noted.
Topic |
URL |
SAS OnlineDoc 9.4 |
|
Base SAS 9.4 |
http://support.sas.com/documentation/onlinedoc/base/index.html |