today: run sas programs on saturn (unix tutorial) runs sas programs on the pc

26
Today: Run SAS programs on Saturn (UNIX tutorial) Runs SAS programs on the PC

Post on 19-Dec-2015

218 views

Category:

Documents


0 download

TRANSCRIPT

Today:

• Run SAS programs on Saturn (UNIX tutorial)

• Runs SAS programs on the PC

Raw Data

Read in Data

Process Data(Create new variables)

Output Data(Create SAS Dataset)

Analyze Data Using Statistical Procedures

Data Step

PROCs

* This is a short example program to demonstrate what a SAS program looks like. This is a comment statement because it begins with a * and ends with a semi-colon ;

DATA demo; INPUT gender $ age marstat $ credits state $ ;

if credits > 12 then fulltime = 'Y'; else fulltime = 'N'; if state = 'MN' then resid = 'Y'; else resid = 'N'; DATALINES;F 23 S 15 MNF 21 S 15 WIF 22 S 09 MNF 35 M 02 MNF 22 M 13 MNF 25 S 13 WIM 20 S 13 MNM 26 M 15 WIM 27 S 05 MNM 23 S 14 IAM 21 S 14 MNM 29 M 15 MN;RUN;

TITLE 'Running the Example Program';PROC PRINT DATA=DEMO ; VAR gender age marstat credits fulltime state ;RUN;

1 DATA demo; Create a SAS dataset called demo2 INPUT gender $ What are the variables age marstat $ credits state $ ;

3 if credits > 12 then fulltime = 'Y'; else fulltime = 'N';

4 if state = 'MN' then resid = 'Y'; else resid = 'N';

Statements 3 and 4 create 2 new variables

5 DATALINES; Tells SAS the data is comingF 23 S 15 MNF 21 S 15 WIF 22 S 09 MNF 35 M 02 MNF 22 M 13 MNF 25 S 13 WIM 20 S 13 MNM 26 M 15 WIM 27 S 05 MNM 23 S 14 IAM 21 S 14 MNM 29 M 15 MN; Tells SAS the data is ending

6 RUN; Tells SAS to run the statements

TITLE 'Running the Example Program';

PROC PRINT DATA=DEMO ; VAR gender age marstat credits fulltime state ;RUN;

PROC MEANS DATA=DEMO ; VAR age credits ;RUN;

PROC FREQ DATA=DEMO ; TABLES gender ;RUN;

Files Generated When SAS Program is RUN

• Log file – a text file listing program statements processed and giving notes, warnings and errors(in UNIX the file will be named fname.log)

• Output file – a text file giving the output generated from the PROCs

(in UNIX the file will be named fname.lst)

Some common procedures:(See also Chapter 20 of C&S)

PROC PRINT• print out your data - always a good idea!!

PROC MEANS• descriptive statistics for continuous data

PROC FREQ• descriptive statistics for categorical data

PROC UNIVARIATE• very detailed descriptive statistics for continuous data

PROC TTEST• performs t-tests (continuous data)

PROC MEANS

PROC MEANS N MEAN MIN MAX MAXDEC=2; VAR age credits; CLASS gender;RUN;

• Displays descriptive statistics of age and number of credits.

• The CLASS statement is optional - it displays the statistics by gender

PROC FREQ

PROC FREQ DATA = DEMO; TABLES gender fulltime; RUN;

• Displays the distribution of gender and full-time status (each distribution separately)

PROC UNIVARIATE

PROC UNIVARIATE DATA = DEMO NORMAL PLOT;

VAR age; RUN;

• Displays descriptive statistics for age

• NORMAL and PLOT are two options that test for normality and display simple graphs

PROC TTEST

PROC TTEST DATA = DEMO; CLASS fulltime; VAR age; RUN;

• Test for a difference in mean age between full-time and non-full-time students

PROC CORR

PROC CORR DATA = DEMO; VAR age credits; RUN;

• Examine the correlation between age and number of credits.

Analyzing by groups - BY statement PROC SORT DATA = DEMO; BY gender; RUN;

PROC MEANS DATA = DEMO; BY gender; VAR age credits; RUN;

• Examines by gender • Need to sort data first• Most procedures allow BY statements

Analyzing by groups - CLASS statement

PROC MEANS DATA = DEMO; CLASS gender; VAR age credits; RUN;

• Examines data by gender• Don’t need to sort first• Can use with PROC TTEST • CLASS statement sometimes not allowed OR is

treated differently in other procedures

Analyzing subgroups - WHERE statement

PROC MEANS DATA = DEMO; WHERE gender = ‘F’; VAR age credits; RUN;

• Only looks at females• Can subset using numeric or character

variables• Can subset in data step using “if” statements

Finding help for SAS

Online SAS manual at

http://v8doc.sas.com

Link on class website.

Using SAS two different ways

• SAS on the PC -Windows environment, pull down menus, nice graphing, color-coded

program editor-If you want to buy it…costs $150 for a yearly user license from http://www1.umn.edu/adcs/site/sas.html

• SAS on Unix -Single window, programs run in batch mode, have to learn some Unix

commands, high resolution graphics must be exported to PC

-While you are taking PH5415 you will have access to SAS via telnet into the biostatistics Unix system. You can use SAS from your home computer (or any computer that has internet access) by dialing into the biostatistics “saturn” computer.

computer name: saturn.biostat.umn.edu

SAS on the PC

Several key windows – See numbered windows on “Window” menu

Editor – where you write or edit SAS code

Log – gives details about code you’ve run

Output – results (if your code didn’t have fatal errors)

Results – manages output

Explorer – manages data sets

PC SAS ENVIRONMENT

Connecting to Biostatistics Computer for PH5415Unix SAS – (batch mode SAS)

saturn.biostat.umn.edu

Home

Office

Computer Lab

BiostatisticsComputer

Via Telnet

SAS on Saturn

Put your code in one file (.sas file)

SAS job is submitted to processor

.log file contains details on your code

.lst file contains output (if there were no fatal errors)

SAS on Saturn

• Copy SAS program to your home directory (or edit a new SAS program)

cp /home/ph5415/programs/tryit.sas ~/

• Type “sas” and the file namesas tryit.sas

• View (“less”) the log and output less tryit.log

• FTP output to PC

SAS on the PC

• Copy SAS program from the web-site

• Open SAS V8 on desktop (double click icon)

• Paste SAS program into Editor

• Click on “Submit” icon or “Submit” from Run menu

• Copy and paste output into a Word document