Before You Begin... 2 Running SAS in Batch Mode... 2 Printing the Output of Your Program... 3 SAS Statements and Syntax... 3



Similar documents
Using Stat/Transfer on the Linux/UNIX Systems

Introduction to Stata... 2 Stata Sessions Running Stata in Batch Mode...2 Running Stata Interactively...3 Data Management...

SPSS: Getting Started. For Windows

DiskPulse DISK CHANGE MONITOR

Moving Files from TSO to a PC

Basics of STATA. 1 Data les. 2 Loading data into STATA

Asset Track Getting Started Guide. An Introduction to Asset Track

Instructions for Configuring a SAS Metadata Server for Use with JMP Clinical

Introduction to SAS on Windows

From The Little SAS Book, Fifth Edition. Full book available for purchase here.

Using the SAS Enterprise Guide (Version 4.2)

1. Base Programming. GIORGIO RUSSOLILLO - Cours de prépara+on à la cer+fica+on SAS «Base Programming»

Creating Cost Recovery Layouts

Introduction to SPSS 16.0

Novell ZENworks Asset Management 7.5

Microsoft Excel 2010 Part 3: Advanced Excel

Quick Start to Data Analysis with SAS Table of Contents. Chapter 1 Introduction 1. Chapter 2 SAS Programming Concepts 7

MyOra 3.0. User Guide. SQL Tool for Oracle. Jayam Systems, LLC

Configuration Manager

Job Scheduler User Guide IGSS Version 11.0

Microsoft Office. Mail Merge in Microsoft Word

Avaya Network Configuration Manager User Guide

Using SPSS, Chapter 2: Descriptive Statistics

SAS Analyst for Windows Tutorial

Horizon Debt Collect. User s and Administrator s Guide

VX Search File Search Solution. VX Search FILE SEARCH SOLUTION. User Manual. Version 8.2. Jan Flexense Ltd.

TIBCO Fulfillment Provisioning Session Layer for FTP Installation

Job Streaming User Guide

Importing and Exporting With SPSS for Windows 17 TUT 117

Chapter 2 The Data Table. Chapter Table of Contents

Setting Up ALERE with Client/Server Data

STATGRAPHICS Online. Statistical Analysis and Data Visualization System. Revised 6/21/2012. Copyright 2012 by StatPoint Technologies, Inc.

SonicWALL GMS Custom Reports

Forms Printer User Guide

Introduction Course in SPSS - Evening 1

UNIX Comes to the Rescue: A Comparison between UNIX SAS and PC SAS

EXST SAS Lab Lab #4: Data input and dataset modifications

9.1 SAS. SQL Query Window. User s Guide

MAS 500 Intelligence Tips and Tricks Booklet Vol. 1

Users Guide. FTP/400 File Transfer API and Remote Command Server Version By RJS Software Systems, Inc.

Business Portal for Microsoft Dynamics GP User s Guide Release 5.1

Directions for using SPSS

Office of History. Using Code ZH Document Management System

Microsoft Access 2010 Part 1: Introduction to Access

WHO STEPS Surveillance Support Materials. STEPS Epi Info Training Guide

The Einstein Depot server

Getting started with the Stata

Simply Accounting Intelligence Tips and Tricks Booklet Vol. 1

EndNote Beyond the Basics

Enterprise Asset Management System

ERserver. iseries. Work management

Tips and Tricks SAGE ACCPAC INTELLIGENCE

Using SSH Secure FTP Client INFORMATION TECHNOLOGY SERVICES California State University, Los Angeles Version 2.0 Fall 2008.

Paper FF-014. Tips for Moving to SAS Enterprise Guide on Unix Patricia Hettinger, Consultant, Oak Brook, IL

SPSS Introduction. Yi Li

The first thing to do is choose if you are creating a mail merge for printing or an merge for distribution over .

How to test and debug an ASP.NET application

Using ATLAS.ti for Qualitative Data Analysis

Legal Notes. Regarding Trademarks KYOCERA Document Solutions Inc.

Welcome to GAMS 1. Jesper Jensen TECA TRAINING ApS This version: September 2006

A Short Introduction to Eviews

UOFL SHAREPOINT ADMINISTRATORS GUIDE

Previewing & Publishing

MPLAB X + CCS C Compiler Tutorial

An Introduction to SPSS. Workshop Session conducted by: Dr. Cyndi Garvan Grace-Anne Jackman

Using SSH Secure Shell Client for FTP

Information Server Documentation SIMATIC. Information Server V8.0 Update 1 Information Server Documentation. Introduction 1. Web application basics 2

Sample Table. Columns. Column 1 Column 2 Column 3 Row 1 Cell 1 Cell 2 Cell 3 Row 2 Cell 4 Cell 5 Cell 6 Row 3 Cell 7 Cell 8 Cell 9.

Sample- for evaluation purposes only. Advanced Crystal Reports. TeachUcomp, Inc.

Introduction to the UNIX Operating System and Open Windows Desktop Environment

USB Recorder User Guide

BlueJ Teamwork Tutorial

Fundamentals of UNIX Lab Networking Commands (Estimated time: 45 min.)

Introduction. Why Use ODBC? Setting Up an ODBC Data Source. Stat/Math - Getting Started Using ODBC with SAS and SPSS

ACCESS Importing and Exporting Data Files. Information Technology. MS Access 2007 Users Guide. IT Training & Development (818)

Access Queries (Office 2003)

Microsoft Office Access 2007 Basics

Evaluator s Guide. PC-Duo Enterprise HelpDesk v5.0. Copyright 2006 Vector Networks Ltd and MetaQuest Software Inc. All rights reserved.

The Center for Teaching, Learning, & Technology

Data Tool Platform SQL Development Tools

Rational Rational ClearQuest

Behavioral Health System

Scribe Online Integration Services (IS) Tutorial

Stored Documents and the FileCabinet

2Creating Reports: Basic Techniques. Chapter

IBM i Version 7.2. Systems management Advanced job scheduler

? Index. Introduction. 1 of 38 About the QMS Network Print Monitor for Windows NT

USB Recorder. User s Guide. Sold by: Toll Free: (877)

The KaleidaGraph Guide to Curve Fitting

There are numerous ways to access monitors:

TimeValue Software Due Date Tracking and Task Management Software

WS_FTP Professional 12

Ultimus and Microsoft Active Directory

SA-9600 Surface Area Software Manual

Using the Bulk Export/Import Feature

Appendix III: SPSS Preliminary

SPSS 12 Data Analysis Basics Linda E. Lucek, Ed.D

What is a Mail Merge?

Table of Contents. Introduction: 2. Settings: 6. Archive 9. Search Browse Schedule Archiving: 18

Introduction to IBM SPSS Statistics

Transcription:

Using SAS In UNIX 2010 Stanford University provides UNIX computing resources on the UNIX Systems, which can be accessed through the Stanford University Network (SUNet). This document provides a basic overview of the SAS data analysis package that is running on the UNIX Systems. Currently, SAS is accessible on public cluster machines, such as Green library clusters and dorm clusters. You can also access SAS remotely (e.g., from Tresidder and Meyer computer clusters) by logging in to a Bramble or Corn. You must have a SUNet ID (Stanford University Network Identifier) to use the UNIX Systems. See the following URL for information on obtaining a SUNet ID: http://www.stanford.edu/dept/as/mais/applications/sunetid/ For basic information on using UNIX, such logging on remotely and selecting the right server, visit the ITS site: https://itservices.stanford.edu/service/unixcomputing Table of Contents Before You Begin... 2 Running SAS in Batch Mode... 2 Printing the Output of Your Program... 3 SAS Statements and Syntax... 3 SAS DATA and PROC Steps...3 Basic Data Management in SAS... 4 Reading in Raw Data...4 Creating a Temporary SAS Data Set...5 Permanent SAS Data Sets...6 Saving SAS Output Data... 8 Examining and Sorting SAS Data Sets... 8 CONTENTS Procedure...8 PRINT Procedure...8 SORT Procedure...9 SAS Options... 9 Moving SAS Files... 10 Using SAS under the X Window System... 11 Entering and Exiting SAS... 11 X Window System Features... 12 SAS Features Under the X Window System... 12 Using SAS / ASSIST... 13 For More Information and Assistance... 14 SAS Documentation and Books... 14 SSDS Software Services at Stanford... 14 Help with the UNIX Systems... 14 Stanford University Social Science Data and Software

Before You Begin Please note that SAS is not case sensitive but the UNIX operating system is case sensitive. In the sample program command lines in this document, bold letters represent SAS or UNIX keywords, which should not be changed. This document assumes that you have logged in to Corn. Therefore the UNIX prompt throughout this document will be shown as corn>. Running SAS in Batch Mode You can execute SAS command files from the UNIX prompt. This is called batch processing. To use batch processing, store the commands in a text file using a UNIX text editor such as EMACS. For more information on using EMACS, see the EMACS Reference Sheet, which is on the Web at: https://itservices.stanford.edu/service/unixcomputing/unix/emacs After storing the commands in a text file using EMACS, submit them to SAS with the following command: For example: corn> sas filename corn> sas census.sas This command processes all the commands in the file called census.sas and normally creates two new files, a log file (a file which has the extension.log) and a list file (a file which has the extension.lst). In this example, the log file is called census.log, and it contains an annotated version of your SAS program, including error messages and other messages regarding the execution of your program. The second file created in this example, census.lst, contains the SAS output, which lists the results produced by the SAS program. Alternatively, sometimes to force SAS to run the program in batch mode, you need to specify using the option of noterminal. The command is written as follows: corn> sas noterminal filename You can view both files using the EMACS text editor, or using the UNIX command more. If SAS does not create a.lst file, it may have found errors that stopped the processing. If this occurs, check the.log file to see which errors you should correct. It is always a good idea to check your.log file to make sure that the program ran correctly. It is a good idea to give your SAS program files a common extension, such as.sas, when naming them. By default, SAS uses 32 megabytes of memory, which is sufficient in most cases. However, if your.log file tells you that it ran out of memory, launch SAS with the following command: SAS MEMSIZE = nm filename; where n is the memory you wish to use in megabytes. 2 - Using SAS in UNIX

Printing the Output of Your Program You can print your output files on one of the laser printers connected to the UNIX workstations at Sweet Hall. The following UNIX command will send your output, census.lst to the printer sweet1. Instead of sweet1, you can specify sweet2, sweet3, sweet4, or sweet5. corn> lpr -h -Psweet1 census.lst SAS Statements and Syntax Construct a SAS program using SAS statements, which are strings of SAS keywords, SAS names, and special characters and operators ending in a semicolon. A statement asks SAS to perform an operation or gives SAS information. Some examples of SAS statements are: INPUT X 15; DATA ONE; Most SAS statements begin with a keyword that identifies what kind of a statement it is. The keyword in the first example is INPUT; it identifies an INPUT statement. Names that you can place in SAS statements include variables, SAS data sets, formats, procedures, options, macros, and file references, among others. In the first example shown above, X is a variable; in the second example, ONE is a data set. Every SAS statement must end with a semicolon, which is a special character. Other special characters and operators that commonly appear in SAS statements include the dollar sign ($), the equals sign (=), and the addition sign (+). For more information on the components of SAS statements, see the SAS Language Guide. (To find out how to get SAS manuals, see For More Information and Assistance later in this document.) Following are general rules for writing SAS statements: Begin all SAS statements with an identifying keyword and end them with a semicolon. SAS statements are free format. This means that they can begin and end anywhere on a line, provided that they end with a semicolon. One statement can continue over several lines, and several statements can occupy the same line. You may use as many blank spaces or lines as you want to separate fields or to separate sets of statements. Use comments and blank lines to set off logical parts of your program. You can include comments anywhere in the program. This is an example of a comment: /* comments are enclosed in these symbols */ SAS DATA and PROC Steps A SAS program is comprised of SAS steps, which are made up of SAS statements. There are two kinds of steps: DATA steps and PROC (procedure) steps. These steps are the building blocks of all SAS programs. Generally, DATA steps read unprocessed or raw data and organize them into a SAS data set. 3 Using SAS in Unix

PROC steps process SAS data sets. A SAS program can consist of a DATA step or a PROC step, or both. Within a program, DATA and PROC steps can appear in any order and with any frequency. DATA Steps: A DATA step includes statements asking SAS to create one or more new SAS data sets and programming statements that perform the manipulations necessary to build these data sets. A DATA step begins with a data statement and can include any number of program statements. You must use a DATA step whenever any transformation of variables is needed. For details about the DATA step, see Basic Data Management in SAS later in this document. PROC Steps: A PROC step asks SAS to execute a procedure that is defined as part of the SAS language, usually with a SAS data set as input. You can add additional statements to the PROC step to give the program more information about the results that you want. Some additional statements are necessary for the proper execution of a procedure, while other statements are optional. For a list of the statements available with each PROC step, see the SAS Procedures Guide. (See For More Information and Assistance later in this document to find out how to get SAS manuals.) A PROC step always starts with a PROC statement. The following are two examples of PROC steps: PROC CONTENTS; PROC MEANS; VAR AGE INCOME; Because a data set is not specified in the examples shown above, SAS will process the last data set mentioned in the program. For this reason, it is good practice to name the SAS data set you want the procedure to analyze. To name the SAS data set, use the following PROC statement: PROC PRINT DATA = datasetname; PROC statements have a wide variety of uses within SAS. Most notably, SAS accesses all statistical analysis routines through PROC statements. Basic Data Management in SAS Reading in Raw Data This section discusses two types of data files: raw data files and SAS data sets. Raw data files are text files that consist of numbers or characters. You can create or view raw data files using a text editor. SAS data sets, also known as system files, cannot be viewed using an editor because they are binary files, not text files. When bringing raw data into SAS, use a DATA step to read the data, as shown in the following example. This process creates a SAS data set that contains the compiled version of the raw data and any computed or recoded variables defined in the DATA step. The SAS System creates two types of data sets: temporary and permanent. A temporary SAS data set exists only for the duration of the current SAS session. You cannot retrieve data stored in a temporary SAS data for use in later SAS sessions. See Permanent SAS Data Sets on page 5 for information about permanent SAS data sets. 4 - Using SAS in UNIX

Creating a Temporary SAS Data Set To create a temporary SAS data set from a raw data file, type the following commands: FILENAME fileref path/filename ; DATA sasname; INFILE fileref; INPUT variablenames; In the example above, the FILENAME statement indicates the location and the name of the UNIX file to be read by the SAS program. The fileref is a nickname by which the file is referenced inside the SAS program; it must be eight characters or fewer and begin with a letter. The filename is the name of the UNIX file that holds your data, which is represented by the fileref. You must specify the filename in the FILENAME line. The filename should be preceded by the path, which tells SAS the directory or subdirectory in which the raw data file is stored. The second line in the example contains the DATA step. In the DATA step, specify the input format, recoding, and computation of new variables. The keyword DATA signifies the beginning of the DATA step. The term sasname is the nickname by which you can subsequently refer to the data set you are creating in this data step. The third line in the example contains the INFILE statement. This statement uses the previously defined fileref to indicate which raw data file to read. Input Statements The fourth line of the preceding example contains the INPUT statement, which lists the names of the variables to be read. There are three main forms of INPUT statements: The LIST input is the simplest input statement. It assumes that the variables are recorded in the same order for each case (observation), but not necessarily in the same column locations. When creating a LIST input, separate values with blanks or commas; you may put several cases on the same row. For example, if you have specified five variables, SAS assumes that a new case begins after each group of five values, regardless of carriage returns in the raw data. Missing values must be represented by a placeholder such as a period. The COLUMN input is used for raw data files in which the variables are in the same column location for every case (observation). When using COLUMN input, list the variable names in the input statement and identify the location of the corresponding data fields in the data lines by specifying the column positions. You can use COLUMN input to skip fields when reading in data; fields can be read in any order. No place holder is required for missing data. The FORMATTED input is used when data requires special instructions to be read correctly. For example, dates or numeric data containing commas should be read using FORMATTED input. Note: SAS has many other INPUT formats, which are described in detail in the SAS Language Guide. (See For More Information and Assistance later in this document for details about getting SAS manuals.) 5 Using SAS in Unix

The following example illustrates how to create a LIST input statement. The input data in the following example is a raw data file called census.data (located in a subdirectory called USinfo), which contains information from a U.S. survey. The name rawdata is used for the fileref and the name usa is used for the SAS data set. The corresponding INPUT statement would look like this example: FILENAME rawdata ~/Country/USinfo/census.data ; DATA usa; INFILE rawdata; INPUT NAME $ SEX $ ID AGE INCOME TEST1 TEST2; This example reads in the raw data as LIST input from a file named census.data in the subdirectory USinfo of the directory Country. It also creates a temporary SAS data set named usa. If no path name is specified, SAS will assume that the file is located in the current directory. Regardless of the directory you are in, you can use the characters ~/ to indicate your home directory. Variables SAS can handle two kinds of variables: numeric and character. A numeric variable has a value that is a number. A character variable may have a value that is a letter, a special character, or a number. When reading in a character variable, you must place a $ after the variable name. In the preceding example, the variables name and sex are character variables. Permanent SAS Data Sets Creating a Permanent SAS Data Set If you are going to use the same data set more than once, it is worth your time to create a permanent SAS data set (also known as a system file) for the data you are using. A permanent SAS data set is saved after the end of the current SAS session and can therefore be used in future programs or sessions. A permanent SAS data set contains the compiled version of the raw data file, as well as any computed or recoded variables. The SAS System identifies permanent SAS data sets using names that consist of two parts, which are separated by a period. The first part of a permanent SAS data set name is called the first-level name, or libref. It identifies the SAS library where the data set is stored. In UNIX, a SAS Library is a directory. The second part of the SAS data set name is called the second-level name, or sasfn. It identifies the specific SAS data set. Both the libref and the sasfn can consist of one to eight characters. When creating a permanent SAS data set, use a LIBNAME statement to associate a libref with the name of the directory where you intend to store the permanent SAS data set. The syntax of the DATA step to create a permanent SAS data set looks like this: FILENAME fileref path/file ; LIBNAME libref path ; DATA libref.sasfn; INFILE fileref; INPUT variable names; 6 - Using SAS in UNIX

The following example creates a permanent SAS data set using the raw data file described in the census.data example on page 5. You will create a permanent SAS data set named survey.ssd01 in the subdirectory USinfo of the directory Country. Note that the extension ssd01 is attached to all permanent SAS data sets. FILENAME rawdata ~/Country/USinfo/census.data ; LIBNAME usa ~/Country/USinfo ; DATA usa.survey; INFILE rawdata; INPUT NAME $ SEX $ ID AGE INCOME TEST1 TEST2; The permanent SAS data set is now in a file named survey.ssd01, which is in the USinfo subdirectory. If you wish to save the SAS system file in your current directory, you can replace the path in the LIBNAME with the notation. In the following example. has replaced ~/Country/USinfo in the LIBNAME statement. LIBNAME usa. ; Using a Permanent SAS Data Set Once you have created a permanent SAS data set, you can use the LIBNAME statement in conjunction with the Data= libref.sasfn option in the PROC step. The following example is a program that produces descriptive statistics, using the permanent SAS data set you created in the previous section. LIBNAME usa Country/USinfo ; PROC MEANS DATA = usa.survey; VAR age income; Use permanent SAS data sets in SAS procedures the same way that you use temporary data sets. Modifying an Existing SAS Data Set Once you have created a permanent SAS data set, use the LIBNAME statement in conjunction with the SET statement to modify an existing SAS data set. Note that the SET command can be used only for SAS data sets. In contrast, INFILE statements can be used only with raw data sets. Following is a program that reads in the permanent SAS data set that you created and calculates a new variable called test3. LIBNAME usa Country/USinfo ; DATA newvar; SET usa.survey; test3 = test1 + test2; The data set newvar is now a temporary SAS data set. If you want to make it into a permanent file that will hold all the variables in usa.survey as well as the newly created variable test3, you must give it a two-level name, such as usa.newvar. The name usa.newvar implies that the data set newvar will be stored in the directory referenced by usa, that is Country/USinfo. 7 Using SAS in Unix

Saving SAS Output Data SAS lets you save the results of a procedure analysis into a SAS data set for further analysis. For example, you might want to plot the residuals of the observations in a regression that you are running at a later time. The following example shows how to save residuals and predicted values from a regression. The general form of the OUTPUT statement can apply to almost any procedure. All the variables in the original data set are included in the new data set, along with variables created in the OUTPUT statement. To see the specific variables that can be saved for each procedure, check the manual for that procedure. To learn how to get SAS manuals, see For More Information and Assistance later in this document. As mentioned earlier, if you want to create a permanent SAS data set, you must give the data set a twolevel name in the OUTPUT statement. LIBNAME usa Country/USinfo ; PROC REG DATA = usa.survey; MODEL z = x1 x2; OUTPUT OUT = res RESIDUAL = zresid PREDICTED = zhat; This program creates a temporary output data set named res. In addition to the variables in the permanent data set survey.ssd01, res contains the variables zhat, whose values are the predicted values of the dependent variable z and zresid, whose values are the residual values of z. Examining and Sorting SAS Data Sets The procedures described in the following sections are described in detail in the SAS Procedures Guide. (See For More Information and Assistance later in this document for information about how to get SAS manuals.) CONTENTS Procedure You can use a CONTENTS procedure to generate more general information from a data set. In the following example, PROC CONTENTS produces a list of the names, positions, formats, and labels for all variables in the survey.ssd01 data set, as well as the date the data set was created. LIBNAME usa Country/USinfo ; PROC CONTENTS DATA = usa.survey; PRINT Procedure Use the PRINT procedure to list the values of some or all variables contained in a SAS data set. You can use the PRINT procedure to check that the data set you have just created actually contains the right variables and observations. You can produce customized reports with PRINT procedure options and statements. The structure of the PRINT procedure is: 8 - Using SAS in UNIX

LIBNAME libref path ; PROC PRINT DATA = libref.sasfn; The above syntax will display all of the variables in the data set. If you only wish to display specific variables, add the VAR statement. In the following example, PROC PRINT displays the variables in the order listed in the VAR statement. In other words, the variables sex and id will be displayed, in that order, from the survey.ssd01 SAS data set. LIBNAME usa Country/USinfo ; PROC PRINT DATA = usa.survey; VAR sex id; Note: The PRINT procedure does NOT send any output to a printer. SORT Procedure The primary function of the SORT procedure is to sort a SAS data set based on the values of a specific variable or variables. You can also use the SORT procedure when you encounter a SAS procedure that requires that your data be sorted before it can be analyzed. For example, the BY command in many SAS procedures runs a separate analysis for each specified value of a variable, but BY group processing requires that the data be sorted on the variable of interest. PROC SORT rearranges the observations in the data set according to the values of the variables in the BY statement. If more than one variable is specified, PROC SORT first sorts the data according to the values of the first variable, then sorts each resulting group according to the second variable, and so on for all successive variables. PROC SORT has the following structure: LIBNAME libref path ; PROC SORT DATA = libref.sasfn; BY variable names; This program sorts the data in the survey.ssd01 data set by the value of the variable id: LIBNAME usa Country/USinfo ; PROC SORT DATA = usa.survey; BY id; SAS Options SAS provides users with a variety of options at the beginning of the program. The most commonly used option is LINESIZE. SAS often generates output that is too wide to fit on 8.5"x11" paper. One solution is to insert the following statement at the beginning of your program: OPTIONS LINESIZE = 80; 9 Using SAS in Unix

Moving SAS Files SAS lets you move SAS data sets from one operating system (UNIX, Windows or Macintosh) to another. This procedure is helpful if you receive data from a location that uses an operating system other than UNIX, or if you want to move your data files from SAS for the Windows or Macintosh to the UNIX operating system or vice versa. Since the form of SAS data sets is specific to the operating system under which the files have been created, moving data sets from one machine to another first requires creating a portable file, which is not specific to one operating system. This section assumes you know how to use FTP (File Transfer Protocol). If you do not and you need to move a SAS data set between different operating systems, see the document FTP at Stanford, which is on the Web at: https://itservices.stanford.edu/service/afs/file-transfer You can also contact the Help Desk (http://helpsu.stanford.edu). To move data from one operating system to another, you will convert the data set to a portable file by running a short SAS export program. After converting the data set to a portable file, you can use binary FTP to move the portable file to the destination computer. Note that you must use binary FTP to move the file. If you are moving a data set from one UNIX account to another, you don t need to export and import; you can move the data set using binary FTP. After you run the export program, you can convert the portable file to a standard data set that is specific to the operating system you are using by running a short SAS import program. This section shows the export and import programs you must execute to move data from one operating system to another. The following example shows how to move a file called survey, which is in the sasfiles subdirectory, by writing it into a portable file called expfile.exp that can be transferred via FTP. It also shows you how to import the file after using FTP to transfer it to a new location. The PROC COPY procedure creates the portable version, expfile.exp, of the SAS data set. 1. Write a SAS export program containing the following commands: LIBNAME mylib ~/Stat/sasfiles ; LIBNAME tranfile XPORT expfile.exp ; PROC COPY IN = mylib OUT = tranfile; SELECT survey; If you type ls at the UNIX prompt you will see that you now have a new file called expfile.exp. This is your portable file, which can by transferred by FTP. Note: You may move a directory that consists of several data sets at once. In the example above, if you delete the line SELECT survey, you will move a subdirectory called sasfiles by writing it into a portable file called expfile.exp. Using this procedure, expfile.exp contains a portable version of all of the data sets in the sasfiles subdirectory. 10 - Using SAS in UNIX

2. FTP the file expfile.exp. Remember to use binary FTP. 3. On the destination computer, create and run the following import program, which saves the data from the portable file back into all the standard data sets from sasfiles, regardless of the number of files you exported previously. This command produces a data set with a format specific to the operating system you are using. The file will be called survey.ssd01, assuming you are now working in the UNIX operating system. LIBNAME tranfile XPORT expfile.exp ; LIBNAME newlib ~/USinfo/new ; PROC COPY IN = tranfile OUT = newlib; Once you have completed these steps, you can erase the portable file (from both accounts). Do not erase the portable file before checking that your data have been imported correctly (for example, by using the PRINT or CONTENTS procedures). Using SAS under the X Window System SAS has a special graphical interface that can be accessed under the X Window System. This interface features pull-down menus, mouse-driven editing capabilities, and extensive online help windows. The X Window System is available on the UNIX workstations located on the second floor of Sweet Hall. The document Using the X Window System provides a general introduction to the X environment. It is on the Web at: https://itservices.stanford.edu/service/unixcomputing/unix It is also possible to use SAS in the X window environment by using an X window emulator software program. This is not recommended for a variety of reasons, including the slowness of running even simple SAS programs. Users who prefer working in a windows environment should consider using either SAS for Macintosh or SAS for Windows. Entering and Exiting SAS If you are using SAS interactively under X, enter SAS by launching X and typing the following command at the UNIX prompt: corn> sas To leave SAS, type the following command at any command line: Command ===> endsas; You can also leave SAS by choosing Exit under the File menu. 11 Using SAS in Unix

X Window System Features The following section describes some of the general features of the X Window System and how to use them. Windows: Windows are screen areas where SAS input and output are placed. There are three basic windows: program, log and list. These SAS windows correspond to the three types of files that are created when you are running SAS in batch mode. The Program window is where your SAS program is created. The Log window corresponds to the.log file created by batch processing. The Output window corresponds to the.lst file. Pull-Down Menus: Pull-down menus are an integral feature of SAS under X. When you click on a menu heading, a list of selections appears. To choose an item from this list, click on the desired item. If an arrow ( >) appears next to a menu item, you must make a selection from another menu level. When you click on most menu items, smaller windows called dialog boxes appear asking you to provide SAS with more information. For example, if you select Print from the File menu, a dialog box will appear on the screen asking you to make a choice about what type of item you want to print. Once you have made a choice from this menu, another dialog box appears asking you to specify which file or SAS object to print. File Filters: File filters are perhaps the most common and most important type of dialog box. Use these boxes to specify the names of the files that you want to save, print, browse or open. In the space labeled File Filter, enter the path for any UNIX directory (the default is your account s home directory, denoted by an asterisk). When you click on the Filter button, a list of all files and subdirectories in that directory will appear in the Files box. SAS Features Under the X Window System The following section describes how to use SAS under the X Window System. Editing SAS Programs: Create your SAS programs in the Program window. SAS under X has some very useful built-in editing capabilities. You can access most of these editing features by clicking on the Edit menu. Saving Your Work: To save a program you have created, click on the File menu and select Save As from options listed. In the dialog box that appears, specify the path and filename for the program, and then click on OK. After you have saved a file, select Save from the File menu to save any changes you make to your file. You can save the contents of the Log and Output windows in the same manner. Executing Your Program: After you have finished creating a SAS program, click on the Locals menu and select Submit to submit the program to SAS for execution. Note: Be sure to save your program before submitting it for execution. Recalling SAS Programs: After you have submitted a program, SAS will erase its contents from the Program window. To retrieve a program that has been submitted for execution, click on the Locals menu and select Recall Text. 12 - Using SAS in UNIX

Using SAS / ASSIST SAS/ASSIST, which is available under the X Window System, allows you to quickly access many SAS commands and capabilities through the use of menus, buttons, and dialog boxes, thereby alleviating the necessity of writing SAS programs. Accessing and Working with SAS / ASSIST To use SAS/ASSIST you must be using SAS in the X Window environment. After launching SAS from the UNIX prompt, click on the Globals pulldown and select Assist. A screen full of graphic objects with labels, which are known as buttons, appears. You can select features of SAS/ASSIST by clicking on these buttons. Major SAS / ASSIST Features The following section provides a brief overview of the buttons available in SAS/ASSIST. Tutorial: SAS/ASSIST has an excellent built-in tutorial that uses windows and dialog boxes to teach beginning users about SAS, its commands, and its capabilities. Data Management: Data Management allows you to import data to SAS, access SAS data sets, browse and edit data interactively, sort data, copy data sets, combine data sets, and more. It is usually much easier to perform these functions through SAS/ASSIST than through traditional SAS programming. Graphics: This button allows you to create bar charts, pie charts, and plots. In addition, SAS has built-in maps that let you view geographic data in actual geographic regions. Using the Graphics button, you can directly access Data Management features to specify which data set(s) are to be used for graphing. Data Analysis: You can access many commonly used statistical functions directly through the SAS/ASSIST Data Analysis function set. Elementary functions include summary statistics, correlations, confidence intervals for means, and frequencies. You can also access linear, logistic, and autocorrelation-corrected regression procedures by clicking on the Regression button. Click on ANOVA to run standard ANOVA and t-tests. You can conduct Canonical Correlations and Principal Components analyses by clicking on Multivariate Analysis. Basic Time Series functions can also be accessed. Note: For many SAS/ASSIST procedures, ASSIST simply programs standard SAS statements together and executes them, using the inputs that you specify through windows and dialog boxes. For data analysis functions, you can actually access the program that ASSIST has used to perform the function. To do so, go to the Program window and select Recall Text from the Locals menu. Accessing programs created by ASSIST this way can give you a good sense of how good SAS programs are organized. Such programs can also be used as a starting point to develop longer or more complex SAS programs. 13 Using SAS in Unix

For More Information and Assistance SAS Documentation and Books Please see the document Resources for Learning SAS on SSDS website. SSDS Software Services at Stanford Software Services provides technical support for SAS users at Stanford. Users can ask questions or make appointments with the consultants via our website. For more information or to contact us, see the web at: http://ssds.stanford.edu/ Help with the UNIX Systems If you have questions about using the UNIX Systems, contact the Help Desk on the web at http://helpsu.stanford.edu. Note: This document is based on SAS 9.2 for Sun Solaris UNIX. Copyright 2010 by The Board of Trustees of the Leland Stanford Junior University. Permission granted to copy for noncommercial purposes, provided we receive acknowledgment and a copy of the document in which our material appears. No right is granted to quote from or use any material in this document for purposes of promoting any product or service. Social Science Data and Software Document revised: 6/30/2010 14 - Using SAS in UNIX