8/2/2019 Introduo ao SAS
1/200
Introduo ao SAS
Profa Connie McManus Pimentel
Universidade de Braslia
8/2/2019 Introduo ao SAS
2/200
Introduo ao SAS/ produtos do SAS SAS Fundamentals
Data Step Proc Steps Informaes sobre programao em SAS
SAS Macro
8/2/2019 Introduo ao SAS
3/200
Base SAS - data management and basic
procedures SAS/STAT - statistical analysis SAS/GRAPH - presentation quality graphics
SAS/OR - Operations research SAS/ETS - Econometrics and Time Series
Analysis SAS/IML - Interactive Matrix Language SAS/SQL Structural query language
8/2/2019 Introduo ao SAS
4/200
Statistical Analysis System, Desenvolvido em 1970s na NorthCarolina State University
SAS Institute Inc. formado em 1976 Software de estatstica mais usado emindustria e universidades
8/2/2019 Introduo ao SAS
5/200
SAS windows escolha WindowTile Horizontally
Type code
Cdigo Submitido
ERROs, AVISOs,
informaes
See output
8/2/2019 Introduo ao SAS
6/200
SAS User Interface
Log Window
ExplorerWindow
Editor Window
Output (no mostrado)
ResultsWindow(not shown)
Run para rodar SAS code
Ajuda
Nova janela
Salvar
Tool bar similar as aplicaes do Windows
8/2/2019 Introduo ao SAS
7/200
Editor
Editor Window tem os dados e programas deSAS
8/2/2019 Introduo ao SAS
8/200
Explorer
ExplorerWindow
Libraries Folder Tem bancos de dados criados no SAS
8/2/2019 Introduo ao SAS
9/200
Libraries Folder
Contedo do LibrariesFolder
Work Folder tem os conjuntosDe dados criados no SAS
Contedo do Work FolderSo conjuntos de dadoscriados no SAS
Via inputting dados eVia criando conjuntos de dadosUsando programas deSAS
8/2/2019 Introduo ao SAS
10/200
Log Window
Log Window tem um relatrio deTodos os comandos submitidos para
SAS e mostra erros
8/2/2019 Introduo ao SAS
11/200
Output Window
Output Window tem outputbaseado em programas de SAS programssubmitido no Editor Window.
8/2/2019 Introduo ao SAS
12/200
8/2/2019 Introduo ao SAS
13/200
SAS Help
8/2/2019 Introduo ao SAS
14/200
Base SAS
The Data Set Processamento Uma etapa a cada vez Libraries & Catalogs
Base SAS SAS Statements (Global, Data, & Proc) Opes de Sistema Formatos & Infomatos Funes
8/2/2019 Introduo ao SAS
15/200
Data Set
Descritor: Nomes das variveis, Labels,Tipos de dados, formatos etcVar Nome data idade altura peso
Obs1
Obs2
8/2/2019 Introduo ao SAS
16/200
Processamento
SAS Systemcompila e depois
exceuta cada stepem sequencia Limite de step
marcado por RUN;
As vezes QUIT; ouo inicio da proximastep
data MYDATA ;
SAS Statements ;
...run ;
proc print
data=MYDATA ;run ;
8/2/2019 Introduo ao SAS
17/200
Step-at-a-time Processing
SAS System Compilae depois executacada etapa em
sequencia O limite da etapa
marcada por RUN; Asvezes QUIT; ou o
inicio da proximaetapa
data MYDATA ;
SAS Statements ;
...
run ;
proc print
data=MYDATA ;
run ;
8/2/2019 Introduo ao SAS
18/200
II. Getting data inThe DATA step
- with DATALINES- with INFILE
The IMPORT procedure
8/2/2019 Introduo ao SAS
19/200
8/2/2019 Introduo ao SAS
20/200
DATA step with DATALINES
Type in Editor window
8/2/2019 Introduo ao SAS
21/200
8/2/2019 Introduo ao SAS
22/200
Submitting code
Highlight and submit code
8/2/2019 Introduo ao SAS
23/200
(A d PROCEDURES)
8/2/2019 Introduo ao SAS
24/200
(A word on PROCEDURES)
Basic structurePROCprocedure DATA=dataset;
;
RUN;
Each statement ends with a semicolon;
E.g.,
PROC print DATA=MissAmericas;
RUN;
8/2/2019 Introduo ao SAS
25/200
DATA step with DATALINES
If you have a lot of lines, typing DATALINES is inconvenient.
8/2/2019 Introduo ao SAS
26/200
DATA step with INFILE
8/2/2019 Introduo ao SAS
27/200
The IMPORT procedureIf there are a lot of variables in different formats,
the INPUT statement can be cumbersome:
IMPORT figures out the variable types (numeric, character, etc.)
and takes variable names (Year, Name, etc.) from the first row.
8/2/2019 Introduo ao SAS
28/200
M ki t SAS d t t
8/2/2019 Introduo ao SAS
29/200
MYLIB points to X:\. You could also say X:\somefolder\ or.
MYLIB.missamericas is a file on X:\
If no library were specified, WORK (temp disk space) would be assumed.
Can you find mylib and missamericas in the SAS Explorer?
Can you find missamericas.sas7bdaton the X: drive?
Making a permanentSAS data set
R t i i t SAS d t
8/2/2019 Introduo ao SAS
30/200
Retrieving a permanent SAS dataset
Quit SAS and relaunch it
See? The contents of mylibarepermanent.
8/2/2019 Introduo ao SAS
31/200
Saving code
Name the contents of the Editor window currently blank
Select the editor window Choose FileSave as
X:\brownbag.sas
Save regularly
8/2/2019 Introduo ao SAS
32/200
The DATA step with SETDefine some new variables
8/2/2019 Introduo ao SAS
33/200
8/2/2019 Introduo ao SAS
34/200
PROC Steps
Data Management Proc Compare Proc Contents
Proc Datasets Proc Format Proc Print Proc Sort
Proc SQL Proc Transpose
Basic Statistics Proc Corr Proc Freq
Proc Means Proc Rank Proc Summary Proc Tabulate
Proc Univariate
8/2/2019 Introduo ao SAS
35/200
Using proc ttestdata Grades.two;
input gender$ x ;cards;
M 51F 38M 49
M 56F 40F 36F 55M 51M 60M 18
F 25;run;
8/2/2019 Introduo ao SAS
36/200
Using proc ttest (cont.)
ods rtf file = C:\Documents and Settings\Owner\MyDocuments\ttestOutput.rtf;
proc ttest data=Grades.two;
class gender;
var x;run;
ods rtf close;Syntax:PROC ttest DATA=datasetname;CLASS factorvars;VAR responsevar;RUN;
8/2/2019 Introduo ao SAS
37/200
DATA A ; INPUT SEXO $ X @@ ; CARDS ; F 75 F 76 F 80 F 77 F 80 F 77 F 76 M 82 M 80 M 85 M 85 M 78 M 87 M 82 PROC TTEST ; CLASS SEXO ;
8/2/2019 Introduo ao SAS
38/200
DATA ARQ ; INPUT TIPO GRUPO $ X Y ; CARDS ; 1 A 32.6 112 1 B 36.4 130 1 A 29.5 106 1 B 36.3 112 1 A 42.5 104 1 B 42.0 115
1 A 44.5 114 1 B 35.3 106 1 A 28.5 105 1 B 41.8 121 2 A 42.7 139 2 B 49.0 139 2 A 41.5 139 2 B 53.0 139 2 A 33.5 139 2 B 49.5 139 2 A 39.3 139 2 B 42.7 139 2 A 47.1 143 2 B 32.9 112 3 A 35.3 124 3 B 40.1 134 3 A 33.6 116 3 B 31.8 133 3 A 41.6 155 3 B 33.8 103 3 A 38.4 146 3 B 40.4 124 3 A 35.9 134 3 B 38.8 123 DATA PARTE ; SET ARQ ; IF TIPO LE 2 ; PROC TTEST DATA = ARQ ; CLASS GRUPO ; PROC TTEST ; CLASS GRUPO ;
VAR X ; BY TIPO ; PROC TTEST DATA = PARTE ; CLASS TIPO ;
8/2/2019 Introduo ao SAS
39/200
Proc Compare
Used to compare onedata set to another
Very flexible
Useful whendeveloping code
proc compare
data=onedata
compare=two ;
var variablelist ;
out=compdata ;
run ;
8/2/2019 Introduo ao SAS
40/200
Proc Contents
Provides informationabout a SAS data set
proc contents
data=mydata ;
run ;
8/2/2019 Introduo ao SAS
41/200
Proc Contents OutputCONTENTS PROCEDURE
Data Set Name: WORK.MYDATA Observations: 4
Member Type: DATA Variables: 2
Engine: V612 Indexes: 0
Created: 16:49 Sunday, June 27, 1999 Observation Length: 16
Last Modified: 16:49 Sunday, June 27, 1999 Deleted Observations: 0
Protection: Compressed: NO
Data Set Type: Sorted: NO
Label:
-----Engine/Host Dependent Information-----Data Set Page Size: 8192
Number of Data Set Pages: 1
File Format: 607
First Data Page: 1
Max Obs per Page: 507
Obs in First Data Page: 4
-----Alphabetic List of Variables and Attributes-----# Variable Type Len Pos
-----------------------------------
1 EXPENSE Num 8 0
2 TOTAL Num 8 8
8/2/2019 Introduo ao SAS
42/200
DATA CLIMA INPUT MES$ 1-3 TEMP 5-8 PRECP UMIDADE; CARDS; JAN 33.4 155 94.3
FEV 34.1 181 95.6 MAR 32.3 101 90.3 ABR 30.3 90 91.4 MAI 27.8 76 75.9 JUN 27.1 84 78.3 JUL 21.2 40 60.8 AGO 19.0 12 58.3
SET 20.1 10 59.8 OUT 22.6 53 66.1 NOV 23.8 55 60.9 DEZ 28.9 89 79.5 ; PROC CONTENTS DATA = CLIMA; RUN; PROC CONTENTS POSITION DATA = CLIMA; RUN;
8/2/2019 Introduo ao SAS
43/200
Proc Datasets
Library contentsmaintenance
copy data sets
delete data sets index data sets etc.
proc datasets
library=libref ;
delete mydata ;
run ;
quit ;
8/2/2019 Introduo ao SAS
44/200
Proc Format
Use proc format tocreate customformats and informats
This is a powerfultechnique fortransforming customdata
proc format ;
value agefmt
low-12=child
13-19=teen
20-high=adult
;
run ;
8/2/2019 Introduo ao SAS
45/200
Proc print
Sends data to output flexible appropriate for must
reporting needs
proc print
data=mydata
split=*;
var varlist ;id varlist ;
by varlist ;
run ;
PROC FORMAT ;
8/2/2019 Introduo ao SAS
46/200
PROC FORMAT ; VALUE REL 1=ADVENTISTA 2=CATOLICA 3=ESPIRITA 4=UMBANDA ; DATA ARQ ; INPUT NOME $ 1-10 SEXO $ IDADE PESO ALTURA RELIGIAO ; IF IDADE = 99 THEN IDADE = . ; IF PESO = 99 THEN PESO = . ;
IF ALTURA = 999 THEN ALTURA = . ; IF RELIGIAO = 9 THEN RELIGIAO = . ; CARDS ; ALFREDO M 14 69 112 2 ALICE F 13 56 84 2 BERNADETE F 14 62 102 2 MARTA F 13 65 98 4 HENRIQUE M 14 63 102 3 MARCOS M 12 57 83 3
HELENA F 12 59 84 2 CLARA F 15 62 102 2 MARCELO M 13 62 84 4 FREDERICO M 12 59 99 3 MATEUS M 12 59 99 2 ELIANE F 11 51 50 2 ALINE F 14 64 90 2 HELOISA F 12 56 77 2 TANIA F 15 66 112 3 FELIPE M 16 72 150 3 ROBERTO M 12 64 128 4 REINALDO M 15 67 113 1 MAURICIO M 11 57 85 2 ANA CELIA F 13 62 108 3 TOMAS M 99 99 85 9 EDUARDO M 15 66 112 2 PROC PRINT ;
8/2/2019 Introduo ao SAS
47/200
Proc Sort
Sorts data by thelisted variable
Sorted data is
necessary formerging and other bygroup processing
proc sort
data=mydata
out=sorted;
by sortvar ;run ;
O d d b
8/2/2019 Introduo ao SAS
48/200
Ordenao de observaes -Comando SORT
DATA ARQX ; INPUT (V1 - V10) (1.) ; CARDS ; 1023480001 5023000101 3103120110 9112311000 6001300011 PROC SORT ; BY V1 ; PROC PRINT ;
8/2/2019 Introduo ao SAS
49/200
Proc SQL
An excellent tool forbeginning SAScoders who are
experienced with SQL Great tool for use withSAS/Access to pulldata from Oracle,
DB2, etc.
proc sql ;
sql statemnts ;
quit ;
8/2/2019 Introduo ao SAS
50/200
Proc Transpose
What to use whenrows is columns andcolumns is rows?
Transpose!
proc transpose
data=mydata ;
by varlist ;
copy varlist ;run ;
8/2/2019 Introduo ao SAS
51/200
Proc Corr
Computes CorrelationCoefficients betweenvariables
Spearman, andKendall, and Pearson,Oh-my!
proc corr
data=mydata ;
run ;
8/2/2019 Introduo ao SAS
52/200
Proc Freq
Counts datafrequencies, preparescross-tabulation
tables and calculatesdescriptive statistics
proc freq
data=mydata ;
tables
var1*var2 ;run ;
8/2/2019 Introduo ao SAS
53/200
: DATA GRUPO ; INPUT NOME $ 1-10 SEXO $ IDADE ALTURA PESO RELIGIAO ; CARDS ; ALFREDO M 14 69 112 2
ALICE F 13 56 84 2 BERNADETE F 14 62 102 2 MARTA F 13 65 98 4 HENRIQUE M 14 63 102 3 MARCOS M 12 57 83 3 HELENA F 12 59 84 2 CLARA F 15 62 102 2
MARCELO M 13 62 84 4 FREDERICO M 12 59 99 3 MATEUS M 12 59 99 2 ELIANE F 11 51 50 2 ALINE F 14 64 90 2 HELOISA F 12 56 77 2 TANIA F 15 66 112 3 FELIPE M 16 72 150 3
ROBERTO M 12 64 128 4 REINALDO M 15 67 113 1 MAURICIO M 11 57 85 2 ANA CELIA F 13 62 108 3 TOMAS M 99 99 85 9 EDUARDO M 15 66 112 2 PROC FREQ ;
8/2/2019 Introduo ao SAS
54/200
DATA GRUPO ; INPUT NOME $ 1-10 SEXO $ IDADE ALTURA PESO RELIGIAO $ ; IF IDADE LE 13 THEN IDADE = 1 ; IF IDADE GT 13 THEN IDADE = 2 ; IF IDADE EQ 99 THEN IDADE = . ; IF PESO EQ 99 THEN PESO = . ; IF ALTURA EQ 999 THEN ALTURA = . ; IF RELIGIAO EQ 9 THEN RELIGIAO = . ; CARDS ; linhas de dados DATA G2 ; SET GRUPO ; IF ALTURA LT 100 ; PROC FREQ DATA = GRUPO ;
TABLES IDADE ; LABEL IDADE 'GRUPOS: ATE 13 E MAIS DE 13 ANOS' ; TITLE 'TABELA DE IDADE PARA O ARQUIVO - GRUPO' ; PROC SORT DATA = GRUPO ; BY SEXO ; PROC FREQ ORDER = FREQ ; TABLES ALTURA PESO ; BY SEXO ; TITLE 'TABELA DE ALTURA E PESO PARA ARQUIVO-GRUPO, POR SEXO' ;
PROC FREQ DATA = G2 ; TITLE 'DATA SET G2 - INCLUI REGISTROS COM ALTURA < 100' ; TITLE2 CRUZAMENTOS COM OPCOES - PRIMEIRA TABELA' ; TABLES SEXO * RELIGIAO / CHISQ EXPECTED ; PROC FREQ ; TITLE2 CRUZAMENTOS COM OPCOES - SEGUNDA TABELA' ; TABLES SEXO * RELIGIAO * IDADE / NOPERCENT ;
8/2/2019 Introduo ao SAS
55/200
Proc Means
Calculates statistics N, NMISS, MIN, MAX,
RANGE, SUM,SUMWGT, MEAN,
USS (soma dosquadrados nocorrigida), CSS(corrigida), VAR, STD(desvio padro),
STDERR (erropadro), CV,SKEWNESS,KURTOSIS, T, PRT
proc means ;
var x ;
by y ;
output out=datamean= ;
run ;
8/2/2019 Introduo ao SAS
56/200
DATA A ;
INPUT TESTE1 TESTE2 LUGAR $ DIA@@ ; CARDS ;
04 54 S 1 07 70 N 1 10 69 N 2 04 52 S 1 07 70 S 2 08 74 N 1 04 60 S 1 07 62 S 2 07 80 N 1 06 61 S 2 06 77 N 2 08 75 N
2 PROC MEANS ;
8/2/2019 Introduo ao SAS
57/200
N, NMISS, MEAN, STD, MIN, MAX,RANGE, SUM, VAR, USS, CSS,STDERR, CV, SKEWNESS, KURTOSIS,
T, PRT, SUMWGT.
8/2/2019 Introduo ao SAS
58/200
: DATA A ; INPUT TESTE1 TESTE2 LUGAR $ DIA @@ ; CARDS ; 04 54 S 1 07 70 N 1 10 69 N 2 04 52 S 1
07 70 S 2 08 74 N 1 04 60 S 1 07 62 S 2 07 80 N 1 06 61 S 2 06 77 N 2 08 75 N 2 PROC MEANS ; VAR TESTE1 TESTE2 ; PROC MEANS DATA = A MAEXDEC = 3 NMISS RANGE USS CSS SKEWNESS KURTOSIS T PRT ; VAR TESTE1 TESTE2 ; TITLE 'ESTATISTICAS SELECIONADAS ; PROC SORT ; BY LUGAR DIA ; PROC MEANS MAXDEC = 3 ; BY LUGAR DIA ; VAR TESTE1 TESTE2 ;
OUTPUT OUT = NOVO MEAN = T1MED T2MED STDERR = T1EM T2EM; TITLE 'ESTATISTICAS POR LUGAR E DIA' ; PROC PRINT DATA = NOVO ; TITLE 'NOVO DATA SET' ;
8/2/2019 Introduo ao SAS
59/200
Teste T Pareado Feita pela PROC MEANS
DIFERENA ENTRE DUAS VARIVEIS INCLUE OPES T E PRT PARA DIFERENA Exemplo: DATA QUEST ; INPUT V1 1-2 V2 4-5 V3 7-8 ; LABEL V1 = NRO DO ANIMAL V2 = PESO ANTES DO TRATAMENTO V3 = PESO DEPOIS DO TRATAMENTO ; DIF = V3 - V2 ; CARDS ; 01 80 82 02 73 71 03 50 45 04 60 65
05 80 75 06 65 67 07 55 60 PROC MEANS MEAN STDERR T PRT ; VAR DIF ;
8/2/2019 Introduo ao SAS
60/200
8/2/2019 Introduo ao SAS
61/200
Proc Summary (resumo dos dados)
A lot like proc means Does not print to
output by default
Other minordifferences
proc summarydata=mydata ;
var varlist ;
classvarlist
;by varlist ;
outputout=newdata
mean= ;run;
8/2/2019 Introduo ao SAS
62/200
Proc Tabulate
Prints descriptivestatistics
Does not create a
output SAS data set
proc tabulatedata=mydata ;
var varlist ;
table,col ;
run ;
8/2/2019 Introduo ao SAS
63/200
The REG procedure
8/2/2019 Introduo ao SAS
64/200
The REG procedure
8/2/2019 Introduo ao SAS
65/200
DATA REGR; INPUT ANO Y X1 X2 @@; CARDS; . . . PROC REG; MODEL Y=X1 X2;
8/2/2019 Introduo ao SAS
66/200
DATA REGR ; INPUT ANO Y X1 X2 @@ ; LABEL Y = INVESTIMENTOS X1 = CAPITAL X2 = LUCROS ; CARDS ; 1935 33.1 1170.6 97.8 1936 45.0 2015.8 104.4 1937 77.2 2803.3 118.0 1938 44.6 2039.7 156.2 1939 48.1 2256.2 172.6 1940 74.4 2132.2 186.6 1941 113.0 1834.1 220.9 1942 91.9 1588.0 287.8 1943 61.3 1749.4 319.9 1944 56.8 1687.2 321.3 1945 93.6 2007.7 319.6 1946 159.9 2208.3 346.0 1947 147.2 1656.7 456.4 1948 146.3 1604.4 543.4 1949 98.3 1431.8 618.3 1950 93.5 1610.5 647.4 1951 135.2 1819.4 671.3 1952 157.3 2079.7 726.1 1953 179.5 2371.6 800.3 1954 189.6 2759.9 888.9 PROC REG ; MODEL Y = X1 X2 ;
roc
8/2/2019 Introduo ao SAS
67/200
roc
8/2/2019 Introduo ao SAS
68/200
EFEITOS A: EFEITO DE A A*B : INTERAO A(B): A DENTRO DE B A|B|C: TODOS OS EFEITOS
PRINCIPAIS E CRUZADOS
8/2/2019 Introduo ao SAS
69/200
Exerccio Bloco Tratamento Peso
1 1 142,36 1 2 144,78 1 3 145,19 1 4 138,88 2 1 138,28 2 2 137,77 2 3 144,44 2 4 130,31 3 1 140,73 3 2 134,06 3 3 136,07 3 4 144,11
CALCULAR MEDIA, ERRO PADRO, DESVIO PADRO, PORTRATAMENTO E POR BLOCO.
Parcelas subdivididas
8/2/2019 Introduo ao SAS
70/200
Parcelas subdivididas4 parcelas (variedades),
4 subparcelas (tratamento de sementes)4 blocos (BANZATTO & KRONKA, 1989, p179)
VARIEDADES(A)
TRATAMENTOSDE SEMENTES
(B)
BLOCOS
1 2 3 4A1 B1
B2B3
B4
42.953.849.5
44.4
41.658.553.8
41.8
28.943.940.7
28.3
30.846.339.4
34.7A2 B1
B2B3B4
53.357.649.864.1
69.669.665.857.4
45.442.441.444.1
35.151.945.451.6
A3 B1B2B3
B4
62.363.464.5
63.6
58.550.446.1
56.1
44.645.062.6
52.7
50.346.750.3
51.8A4 B1
B2B3B4
75.470.368.871.6
65.667.365.369.4
54.057.645.656.6
52.758.551.047.4
ARQUIVO DE
8/2/2019 Introduo ao SAS
71/200
ARQUIVO DEDADOS
DATA TESTE3; INFILE "C:PS.DAT"; DO V=1 TO 4; DO T= 1 TO 4; DO B=1 TO 4; INPUT Y @; OUTPUT; END; END; END; PROC ANOVA; CLASS V T B; MODEL Y = B V B*V T V*T; TEST H=B V E=B*V; MEANS V T V*T; RUN;
42.953.849.544.4
41.658.553.841.8
28.943.940.728.3
30.846.339.434.7
53.357.6
49.864.1
69.669.6
65.857.4
45.442.4
41.444.1
35.151.9
45.451.662.363.464.563.6
58.550.446.156.1
44.645.062.652.7
50.346.750.351.8
75.470.3
68.871.6
65.667.3
65.369.4
54.057.6
45.656.6
52.758.5
51.047.4
PROC GLM
8/2/2019 Introduo ao SAS
72/200
PROC GLM
Experimento com 3 tratamentos,
8/2/2019 Introduo ao SAS
73/200
Experimento com 3 tratamentos,com n1 = 3, n2 = 2 e n3 = 1
repeties (SEARLE, p. 219) data teste4; input trat y ; cards; 1 101 1 105
1 94 2 84 2 88 3 32 ; title "exemplo 4 curso do SAS" PROC PRINT DATA = TESTE4; PROC GLM; CLASS TRAT; MODEL Y = TRAT; MEANS TRAT / TUKEY; CONTRAST "1 & DEMAIS" TRAT 3 - 2 - 1, "2 & 3 " TRAT 0 2 - 2 ; RUN;
Sem interao efeitos fixos
8/2/2019 Introduo ao SAS
74/200
Sem interao - efeitos fixos. DATA TESTE5; INPUT REPR RAO Y; CARDS;
1 1 5 1 1 6 1 2 2 1 2 3 2 1 2 2 1 3 2 1 5 2 1 6 2 1 7
2 2 8 2 2 8 2 2 9 3 1 3 3 2 4 3 2 4 3 2 6 3 2 6 3 2 7 ; TITLE " EXEMPLO 5 CURSO SAS "; PROC PRINT DATA = TESTE5; PROC GLM; CLASS REPR RAO; MODEL Y = REPR RAO; MEANS REPR RAO/DUNCAN;
Com interao - efeitos aleatrios
8/2/2019 Introduo ao SAS
75/200
Com interao efeitos aleatrios DATA TEST6 INPUT REPR RAO Y CARDS; 1 1 5 1 1 6 1 2 2 1 2 3 2 1 2 2 1 3 2 1 5 2 1 6 2 1 7
2 2 8 2 2 8 2 2 9 3 1 3 3 2 4 3 2 4 3 2 4 3 2 6 3 2 6 3 2 7 ; TITLE " EXEMPLO 6 CURSO SAS"; PROC GLM; CLASS REPR RAO; MODEL Y = REPR RAO REPR*RAO;
MEANS REPR*RAO / TUKEY; RANDOM REPR RAO REPR*RAO / Q;
Efeito da rao no crescimento de suinos
8/2/2019 Introduo ao SAS
76/200
Efeito da rao no crescimento de suinoscomo covarincia o peso inicial.
----------------------------------------------------------------------------------------------------------------- RAO 1 RAO 2 RAO 3 --------------------------------- -------------------------------- ------------------------------------- PESO IN. GANHO PESO PESO IN. GANHO PESO PESO IN. GANHO PESO ------------------------------------------------------------------------------------------------------------------- 5 3 4 5 8 7 9 5 7 6 7 6 11 6 0 2 3 4 3 2 8 7 2 3 10 8 8
6 2 3 2
4 12 9 5 8 -----------------------------------------------------------------------------------------------------------------
DATA TESTE7;
8/2/2019 Introduo ao SAS
77/200
; INPUT TRAT W Y ; CARDS; 1 5 3 1 9 5 1 11 6
1 3 2 2 4 5 2 7 6 2 0 2 2 8 7 2 10 8 2 2 3 2 12 9 2 5 8
3 8 7 3 7 6 3 3 4 3 2 3 3 8 6 3 2 4 ; TITLE "EXEMPLO 7 DO SAS"; PROC PRINT
DATA = TESTE7; PROC GLM; CLASS TRAT; MODEL Y = TRAT W ; RUN;
8/2/2019 Introduo ao SAS
78/200
VI. Getting results outThe Output window
The Output Delivery System
The EXPORT procedure
8/2/2019 Introduo ao SAS
79/200
Save the output window
Click in the output window Choose FileSave As
8/2/2019 Introduo ao SAS
80/200
Saving output using Output delivery
8/2/2019 Introduo ao SAS
81/200
Saving output using Output deliverySystem (ODS)
Goal: To provide more flexibility in producing outputfrom SAS data steps and procedures. Using ODS, output can be produced in the following
formats: rtf, pdf, postscript, html. Many procedures produce ODS objects, which can
then be output in any of these formats. You can open an ODS output stream with the ODS
command and a destination keyword. For example, toproduce rtf formatted output from the print procedure:ods rtf file=C:\Documents and Settings\Owner\MyDocuments\printOutput.rtf;proc print data=Grades.one;
run;ods rtf close;
Whats the outputs name?
8/2/2019 Introduo ao SAS
82/200
Saving the output
8/2/2019 Introduo ao SAS
83/200
Sa g t e output
int_slopeis a data set
Can you find it?
Doctoring the output
8/2/2019 Introduo ao SAS
84/200
g p
The EXPORT procedure
8/2/2019 Introduo ao SAS
85/200
The EXPORT procedure
Results.xlsis an Excel file. Can you find it?
8/2/2019 Introduo ao SAS
86/200
IV. Graphics
PROC GPLOT
8/2/2019 Introduo ao SAS
87/200
PROC GPLOT
8/2/2019 Introduo ao SAS
88/200
PROC GPLOT
8/2/2019 Introduo ao SAS
89/200
PROC GPLOT
8/2/2019 Introduo ao SAS
90/200
PROC GPLOT
8/2/2019 Introduo ao SAS
91/200
PROC GPLOT
8/2/2019 Introduo ao SAS
92/200
PROC GHART
8/2/2019 Introduo ao SAS
93/200
PROC GHART
8/2/2019 Introduo ao SAS
94/200
8/2/2019 Introduo ao SAS
95/200
PROC GHART
8/2/2019 Introduo ao SAS
96/200
PROC GHART
8/2/2019 Introduo ao SAS
97/200
Proc Gchart
8/2/2019 Introduo ao SAS
98/200
Proc Gchart If you need to make bar charts, use proc
gchart. Use can use axis options like ingplot and the pattern global option toset the bar fill colors and patterns.
If your plotting variable is categorical you
get one bar per value. If you are plottinga continuous variable the procedure willgroup the data for you; unless you tell itotherwise.
pattern1 color = blue;procgchart;
vbar boys /discrete; run;
Don't group
Proc Gchart
8/2/2019 Introduo ao SAS
99/200
Proc Gchart(2)
Notice that the default statistic forvbar is frequency. Additionalstatistics you can request includecfreq (cumulative frequency),
cpercent (cumulative percent), andpercent. You can get these byincluding this on the vbar line:
/ type= statisticName
procgchart;vbar month ;
run;
Proc Gchart
8/2/2019 Introduo ao SAS
100/200
Proc Gchart(3)
You can tell it how many groupsyou want like this:
procgchart;
vbar month /levels = 4;
run;
quit;
Proc Gchart
8/2/2019 Introduo ao SAS
101/200
Proc Gchart (4)
Formats can define groupsprocformat;
value season
2-4 = "Spring"5-7 = "Summer";
run;
procgchart;
format month season.;
vbar month /discrete;
run;
P G h
8/2/2019 Introduo ao SAS
102/200
procformat;value season
11, 12, 1 = "Winter"
2-4 = "Spring"
5-7 = "Summer"8-10 = "Fall";
run;
/*months in each quarter*/
procgchart;format month season.;
vbar month / discrete;
run;
quit;
Proc Gchart (5)
Proc Gchart
8/2/2019 Introduo ao SAS
103/200
Proc Gchart(6)
You can specify two different statistics one toappear just above or below the bars:
procgchart;format month season.;
vbar month/outside=cfreq inside=freq;
run;
quit;
Basic HBAR
8/2/2019 Introduo ao SAS
104/200
Basic HBAR
If you do a hbar you get frequency, cumulativefrequency, percent, and cumulative percent informationby default.
If you want a different statistic just include it after the /
If you dont want statistics include / nostatsprocgchart;
hbar boys /discrete;
run;
Filling in Colors
8/2/2019 Introduo ao SAS
105/200
Filling in Colors
On the chart line you can specify fill = x to usecross hatched fill patterns or fill = s for solid fillcolors. Use solid colors if possible.
You can set how patterns are applied by using
patternid = on the chart line. Patternid can takethese values by, group, midpoint, subgroup.Midpoint gives you a different pattern for eachbar (or pie slice). Avoid using more than 9
different color/pattern combinations.
More on Bar Charts
8/2/2019 Introduo ao SAS
106/200
More on Bar Charts
You can group by subvariables:procgchart data = dxinfo;
hbar ca_site / discrete group =sex;
vbar ca_site / discrete group =sex;where sex ne 9;
run;
quit;
FREQ.CUM.
F REQ. PCT .CUM.PC T.
Ca n c e r S i t e a s Co d e #SE X1 Ma l e
6 I n t e s t i n e5 Bl a d d e r
4 Ce r v i x3 Ut e r u s / En d o
2 B r e a s t1 Ov a r y
8/2/2019 Introduo ao SAS
107/200
2 F e ma l e9 9 U n k n o wn
9 8 Ov a r i a n T umo r - B en i g9 7 Ov a r i a n Cy s t
9 6 Me n t a l Re t a r d a t i o n5 5 Br e a s t Di s e a - Be n i g n
5 4 Oo p h o r e c t o my - Ot h e r5 3 Ma s t e c t o my
5 2 Hy s t e r e c t o my5 0 Oo p h o r e c t o my - P r o p h
2 6 Pe r i t o n e u m2 5 Ur i n a r y NOS
2 4 Th y r o i d2 3 S t o ma c h / E s o p h
2 2 Sk i n2 1 Pa n c r e a s
2 0 Ot h er - Sp ec i f i e d1 9 Ot h e r , NOS
1 8 L y mp h o ma / My e l o ma
1 7 L u n g1 6 L i v e r
1 5 L e u k e mi a1 4 K i d n e y
1 3 H e a d & N e c k1 2 M a l e N OS
1 0 F e m a l e N OS9 C NS
8 B o n e / S a r c o ma7 Pr o s t a t e
9 9 U n k n o wn9 8 Ov a r i a n T umo r - B en i g
9 7 Ov a r i a n Cy s t9 6 Me n t a l Re t a r d a t i o n
5 5 Br e a s t Di s e a - Be n i g n5 4 Oo p h o r e c t o my - Ot h e r
5 3 Ma s t e c t o my5 2 Hy s t e r e c t o my
5 0 Oo p h o r e c t o my - P r o p h2 6 Pe r i t o n e u m
2 5 Ur i n a r y NOS2 4 Th y r o i d
2 3 S t o ma c h / E s o p h2 2 Sk i n
2 1 Pa n c r e a s2 0 Ot h er - Sp ec i f i e d
1 9 Ot h e r , NOS1 8 L y mp h o ma / My e l o ma
1 7 L u n g1 6 L i v e r
1 5 L e u k e mi a1 4 K i d n e y
1 3 H e a d & N e c k1 2 M a l e N OS
1 0 F e m a l e N OS9 C NS
8 B o n e / S a r c o ma7 Pr o s t a t e
6 I n t e s t i n e5 Bl a d d e r
4 Ce r v i x3 Ut e r u s / En d o
2 B r e a s t
1 Ov a r y
FREQUENCY
0 2 0 4 0 6 0 8 0 1 0 0 1 2 0 1 4 0 1 6 0 1 8 0
FREQUENCY
1 5 0
1 6 0
1 7 0
1 8 0
8/2/2019 Introduo ao SAS
108/200
0
1 0
2 0
3 0
4 0
5 0
6 0
7 0
8 0
9 0
1 0 0
1 1 0
1 2 0
1 3 0
1 4 0
Ca n c e r S i t e a s Co d e #
SE X1 Ma l e 2 F e ma l e
1
O
v
a
r
y
2
B
r
e
a
s
t
3
U
t
e
r
u
s
/E
n
d
o
4
C
e
r
v
i
x
5
B
l
a
d
d
e
r
6
I
n
t
e
s
t
in
e
7
P
r
o
s
t
a
te
8
B
o
n
e
/
S
ar
c
o
m
a
9
C
N
S
1
0
F
e
m
a
l
e
N
O
S
1
2
M
a
l
e
NO
S
1
3
H
e
a
d
&
N
e
c
k
1
4
K
i
d
n
e
y
1
5
L
e
u
k
e
mi
a
1
6
L
i
v
e
r
1
7
L
u
n
g
1
8
L
y
m
p
h
om
a
/
M
y
e
l
o
m
a
1
9
O
t
h
e
r
,
N
O
S
2
0
O
t
h
e
r
-S
p
e
c
i
f
i
e
d
2
1
P
a
n
c
r
ea
s
2
2
S
k
i
n
2
3
S
t
o
m
a
ch
/
E
s
o
p
h
2
4
T
h
y
r
o
id
2
5
U
r
i
n
a
ry
N
O
S
2
6
P
e
r
i
t
on
e
u
m
5
0
O
o
p
h
o
re
c
t
o
m
y
-
P
r
o
p
h
5
2
H
y
s
t
e
re
c
t
o
m
y
5
3
M
a
s
t
e
ct
o
m
y
5
4
O
o
p
h
o
re
c
t
o
m
y
-
O
t
h
e
r
5
5
B
r
e
a
s
t
D
i
s
e
a
-
B
e
n
i
g
n
9
6
M
e
n
t
a
l
R
e
t
a
r
d
a
t
i
o
n
9
7
O
v
a
r
i
an
C
y
s
t
9
8
O
v
a
r
i
an
T
u
m
o
r
-
B
e
n
i
g
9
9
U
n
k
n
o
wn
1
O
v
a
r
y
2
B
r
e
a
s
t
3
U
t
e
r
u
s
/E
n
d
o
4
C
e
r
v
i
x
5
B
l
a
d
d
e
r
6
I
n
t
e
s
t
in
e
7
P
r
o
s
t
a
te
8
B
o
n
e
/
S
ar
c
o
m
a
9
C
N
S
1
0
F
e
m
a
l
e
N
O
S
1
2
M
a
l
e
NO
S
1
3
H
e
a
d
&
N
e
c
k
1
4
K
i
d
n
e
y
1
5
L
e
u
k
e
mi
a
1
6
L
i
v
e
r
1
7
L
u
n
g
1
8
L
y
m
p
h
om
a
/
M
y
e
l
o
m
a
1
9
O
t
h
e
r
,
N
O
S
2
0
O
t
h
e
r
-S
p
e
c
i
f
i
e
d
2
1
P
a
n
c
r
ea
s
2
2
S
k
i
n
2
3
S
t
o
m
a
ch
/
E
s
o
p
h
2
4
T
h
y
r
o
id
2
5
U
r
i
n
a
ry
N
O
S
2
6
P
e
r
i
t
on
e
u
m
5
0
O
o
p
h
o
re
c
t
o
m
y
-
P
r
o
p
h
5
2
H
y
s
t
e
re
c
t
o
m
y
5
3
M
a
s
t
e
ct
o
m
y
5
4
O
o
p
h
o
re
c
t
o
m
y
-
O
t
h
e
r
5
5
B
r
e
a
s
t
D
i
s
e
a
-
B
e
n
i
g
n
9
6
M
e
n
t
a
l
R
e
t
a
r
d
a
t
i
o
n
9
7
O
v
a
r
i
an
C
y
s
t
9
8
O
v
a
r
i
an
T
u
m
o
r
-
B
e
n
i
g
9
9
U
n
k
n
o
wn
Rotate the labels
8/2/2019 Introduo ao SAS
109/200
Rotate the labels
I frequently want to rotate the label on thegrouping axis.
axis1 label = (angle = 90 );
procgchart data = Chart3;
title "Chart3: Chart Parturition (Birth)";
hbar _all_ / discrete maxis = axis1;
run;
quit; title; axis1;
FREQ.
CUM.
F REQ. PCT .
CUM.
PCT.
1 1 0 . 0 5 0 . 0 5
6 5 6 6 3 0 9 3 1 4
A GE 9 9 : A GE ON 1 / 1 / 9 9
4 0
* * E r r o r * *
8/2/2019 Introduo ao SAS
110/200
6 5 6 6 3 . 0 9 3 . 1 4
8 0 1 4 6 3 . 8 1 6 . 9 5
6 7 2 1 3 3 . 1 9 1 0 . 1 4
7 7 2 9 0 3 . 6 6 1 3 . 8 0
7 6 3 6 6 3 . 6 2 1 7 . 4 2
9 3 4 5 9 4 . 4 3 2 1 . 8 5
7 1 5 3 0 3 . 3 8 2 5 . 2 3
9 1 6 2 1 4 . 3 3 2 9 . 5 6
7 0 6 9 1 3 . 3 3 3 2 . 8 9
6 7 7 5 8 3 . 1 9 3 6 . 0 8
1 1 3 8 7 1 5 . 3 8 4 1 . 4 6
9 8 9 6 9 4 . 6 6 4 6 . 1 2
8 5 1 0 5 4 4 . 0 5 5 0 . 1 7
7 2 1 1 2 6 3 . 4 3 5 3 . 5 9
7 8 1 2 0 4 3 . 7 1 5 7 . 3 1
9 4 1 2 9 8 4 . 4 7 6 1 . 7 8
9 1 1 3 8 9 4 . 3 3 6 6 . 1 1
7 3 1 4 6 2 3 . 4 7 6 9 . 5 9
6 3 1 5 2 5 3 . 0 0 7 2 . 5 8
4 8 1 5 7 3 2 . 2 8 7 4 . 8 7
6 5 1 6 3 8 3 . 0 9 7 7 . 9 6
6 0 1 6 9 8 2 . 8 6 8 0 . 8 2
6 2 1 7 6 0 2 . 9 5 8 3 . 7 7
4 5 1 8 0 5 2 . 1 4 8 5 . 9 1
4 0 1 8 4 5 1 . 9 0 8 7 . 8 2
7 6 1 9 2 1 3 . 6 2 9 1 . 4 3
4 5 1 9 6 6 2 . 1 4 9 3 . 5 7
5 5 2 0 2 1 2 . 6 2 9 6 . 1 9
4 9 2 0 7 0 2 . 3 3 9 8 . 5 2
3 1 2 1 0 1 1 . 4 8 1 0 0 . 0 06 9
6 8
6 7
6 6
6 5
6 4
6 3
6 2
6 1
6 0
5 9
5 8
5 7
5 6
5 5
5 4
5 3
5 2
5 1
5 0
4 9
4 8
4 7
4 6
4 5
4 4
4 3
4 2
4 1
4 0
FREQUENCY
0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9 0 1 0 0 1 1 0 1 2 0
FREQ.
CUM.
F REQ. PCT .
CUM.
PCT.
1 1 0 . 0 5 0 . 0 5
6 5 6 6 3 . 0 9 3 . 1 44 0
* * E r r o r * *
8/2/2019 Introduo ao SAS
111/200
8 0 1 4 6 3 . 8 1 6 . 9 5
6 7 2 1 3 3 . 1 9 1 0 . 1 4
7 7 2 9 0 3 . 6 6 1 3 . 8 0
7 6 3 6 6 3 . 6 2 1 7 . 4 2
9 3 4 5 9 4 . 4 3 2 1 . 8 5
7 1 5 3 0 3 . 3 8 2 5 . 2 3
9 1 6 2 1 4 . 3 3 2 9 . 5 6
7 0 6 9 1 3 . 3 3 3 2 . 8 9
6 7 7 5 8 3 . 1 9 3 6 . 0 8
1 1 3 8 7 1 5 . 3 8 4 1 . 4 6
9 8 9 6 9 4 . 6 6 4 6 . 1 2
8 5 1 0 5 4 4 . 0 5 5 0 . 1 7
7 2 1 1 2 6 3 . 4 3 5 3 . 5 9
7 8 1 2 0 4 3 . 7 1 5 7 . 3 1
9 4 1 2 9 8 4 . 4 7 6 1 . 7 8
9 1 1 3 8 9 4 . 3 3 6 6 . 1 1
7 3 1 4 6 2 3 . 4 7 6 9 . 5 9
6 3 1 5 2 5 3 . 0 0 7 2 . 5 8
4 8 1 5 7 3 2 . 2 8 7 4 . 8 7
6 5 1 6 3 8 3 . 0 9 7 7 . 9 6
6 0 1 6 9 8 2 . 8 6 8 0 . 8 2
6 2 1 7 6 0 2 . 9 5 8 3 . 7 7
4 5 1 8 0 5 2 . 1 4 8 5 . 9 1
4 0 1 8 4 5 1 . 9 0 8 7 . 8 2
7 6 1 9 2 1 3 . 6 2 9 1 . 4 3
4 5 1 9 6 6 2 . 1 4 9 3 . 5 7
5 5 2 0 2 1 2 . 6 2 9 6 . 1 9
4 9 2 0 7 0 2 . 3 3 9 8 . 5 2
3 1 2 1 0 1 1 . 4 8 1 0 0 . 0 06 9
6 8
6 7
6 6
6 5
6 4
6 3
6 2
6 1
6 0
5 9
5 8
5 7
5 6
5 5
5 4
5 3
5 2
5 1
5 0
4 9
4 8
4 7
4 6
4 5
4 4
4 3
4 2
4 1
FREQUENCY
0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9 0 1 0 0 1 1 0 1 2 0
Bad charts
8/2/2019 Introduo ao SAS
112/200
Bad charts.
SAS will also let you specify subgroups (to givestacked subgroups). Do not do these graphics.People are bad at untangling the relativeheights. There are great graphics for showing
subgroups but SAS cant do them. SAS will let you generate pie charts by
specifying pie instead of hbar or vbar but dont.There is good psychological research
suggesting people are lousy at judging angles.Exploded pie diagrams are even worse.
Scatter Plots
8/2/2019 Introduo ao SAS
113/200
Scatter Plots
You can get simple scatter plots out of theanalysis procedure proc reg. For fancyplots use proc gchart.
VD data
8/2/2019 Introduo ao SAS
114/200
VD data (valentines day)
You can get great looking scatter plots with procgplot.d f
8/2/2019 Introduo ao SAS
115/200
data foo;
do month = 1 to 12;
input kids boys @@;girls = kids - boys;
output;
end;
datalines;0 0 1 1 2 2 1 0 1 0 2 1
2 1 2 0 1 1 1 0 6 2 0 0
;
run;procgplot;*Plot kids on vertical axis & months on horizontal;
plot kids * month;
run; quit ;
8/2/2019 Introduo ao SAS
116/200
The Font
8/2/2019 Introduo ao SAS
117/200
The Font
If you do not like the default font you change itwith the graphic global option ftext ..
goptions ftext='Verdana';
... or you can specify a different font for differentparts of the graphic. I will show this later.
kids
6
8/2/2019 Introduo ao SAS
118/200
0
1
2
3
4
5
month
1 2 3 4 5 6 7 8 9 10 11 12
Simple Axis Values
8/2/2019 Introduo ao SAS
119/200
Simple Axis Values
By including /haxis= and/or vaxis= you canchange the ranges on the axes.
procgplot;
*this plots the same axes but you couldchange the ranges and/or values bymodifying the values after the equalsigns;
plot kids * month /vaxis = 0123456
haxis = 1 to 12 by 1;
run; quit ;
Simple Tick Marks
8/2/2019 Introduo ao SAS
120/200
Simple Tick Marks
If you want to control the number of small(minor) tick marks you can use the optionsvminor and/or hminor on the plot statement line.
For example to remove the minor tick marks onthe previous graph do this:
plot kids * month /
vaxis = 0123456 vminor = 0
haxis = 1 to 12 by 1 hminor = 0;
Symbols
8/2/2019 Introduo ao SAS
121/200
Symbols
You can change theplot symbols bysetting a goptions
option.symbol1 value=star;
procgplot;
plot kids * month;
run;
quit;
From SAS OnLineDoc V8. Copyright (c)1999 SAS Institute Inc., Cary, NC,USA. All rights reserved.
8/2/2019 Introduo ao SAS
122/200
Adding Markers
8/2/2019 Introduo ao SAS
123/200
Adding Markers
There is a SAS font called markerthat hassymbols. Set the font and use the singleletters below to add in a symbol.
From SAS OnLineDoc V8. Copyright (c) 1999 SAS Institute Inc., Cary, NC, USA. All rights reserved.
Symbols
8/2/2019 Introduo ao SAS
124/200
Symbols
You can use custom symbols like this:
symbol1 font=marker value= N
color=red height = 3;procgplot;
plot kids * month;
run;
quit;
This letter was
chosen from the
previous slide. Note
that it is a capital
letter and it is not inquotes.
8/2/2019 Introduo ao SAS
125/200
Other Symbol Stuff
8/2/2019 Introduo ao SAS
126/200
y
If you need to join the symbols, set interpol =join or interpol = spline (a smoothed line).
If you need a bigger plotting symbol set height=
aNumber If you need a thicker line set width= aNumber Symbol options last for the duration of your SAS
session and they are additive. So you can set and
reset different aspects of the symbol on differentlines of you code.
Reset Symbols
8/2/2019 Introduo ao SAS
127/200
y
To reset an option, follow it by an equal signsymbol1 font=;
If it is in a list follow the equal with a comma;symbol1 font=, value = dot;
To reset all aspects of a symbol type its namefollowed by a semicolon;
symbol1;
To reset all symbols type this:goptions reset=symbol;
Symbol Options at a Glance
8/2/2019 Introduo ao SAS
128/200
y p Value is abbreviated v= and the default is PLUS Height is abbreviated h= and the default is 1 cell Interpol is abbreviated i= and the default is none Width is abbreviated w= and the default is 1 pixel
Color is abbreviated c= and the default is black You specify the size of units for height and width by
including the word cell (character size) cm(centimeters), in (inches) pct (percent of the display
area) or pt (points) after the number of units. ALWAYS specify a color.
Two Symbols
8/2/2019 Introduo ao SAS
129/200
y
You can overlay two plots and use differentsymbols for each like this:
goptions reset=all;
symbol1 height=3 width=3;
symbol1 font=marker value=Q color=blue ;
symbol2 height=3 width=3;
symbol2 font=marker value=R color=pink ;
procgplot;
plot boys * month
girls * month/overlay;
run;
quit;
8/2/2019 Introduo ao SAS
130/200
Axis options
8/2/2019 Introduo ao SAS
131/200
axis1 order = (1 to 12 by 1) /*what values*/
/* appearance of label */label=(height=5pct font='Times New Roman')
width=3
major=(width = 3) /*width of ticks */
minor=none /* no minor ticks */
value=(height = 5pct font='Times New Roman');
procgplot;
label Month = "Birth Month";
plot boys * month
girls * month/overlay haxis = axis1;
run;quit;
Use the custom axis.
8/2/2019 Introduo ao SAS
132/200
goptions reset= all;symbol1 font=marker value=Q color=blue h=3 w=3;
symbol2 font=marker value=R color=pink h=3 w=3;
i 1 d (1 t 12 b 1)
8/2/2019 Introduo ao SAS
133/200
axis1 order = (1 to 12 by 1)
label = (height=5pct font='Times New Roman')
width = 3major = (Width = 3) minor = none
value = (height = 5pct f='Times New Roman');
axis2 order = (1 to 5 by 1)
label = (height=5pct font='Times New Roman')
width = 3major = (Width = 3)
minor = none
value = (height = 5pct f='Times New Roman');
procgplot;
label Month = "Birth Month"; label boys = "Kids";
plot boys * month
girls * month/overlay haxis = axis1 vaxis = axis2;
run;quit;
Set from 1 to 5 not 0 to 5
8/2/2019 Introduo ao SAS
134/200
8/2/2019 Introduo ao SAS
135/200
8/2/2019 Introduo ao SAS
136/200
Exporting Images
8/2/2019 Introduo ao SAS
137/200
p g g If you need to save the image:
put your plot inside ODS html code use edit menu and pick copy
If you want to save a single high resolution copy of
the picture (that can be resized without changingthe appearance of the picture) include this codebefore your plot:
filename theFile "C:\projects\blah.cgm";
goptions device=cgmOf97L; /*or =gif */
goptions gsfname=theFile gsfmode=replace;
/* some SAS/GRAPH stuff */
goptions reset=all;
Saving Images
8/2/2019 Introduo ao SAS
138/200
g g
You can save your images in a SAS graphicscatalog in a permanent library by including:gout=theLibname.theCatalogName on the procgplot line.
If you dont specify an output catalog yourpictures will be saved in the work library in acatalog called Gseg.
If the graphics catalog exists the new graphicswill be added to it. If does not exist, it will becreated for you.
You can use the SAS explorer to look at files in
a graphics catalog
Interaction plot
8/2/2019 Introduo ao SAS
139/200
data blah;input hasCancer race test;
datalines;
0 0 6.8
0 1 5.81 0 6.4
1 1 9.3
;
run;
procgplot;
plot test * hasCancer = race;
run;
8/2/2019 Introduo ao SAS
140/200
u ;
quit;
symbol1 interpol = join color = black;
symbol2 i = join color = red;
l t
8/2/2019 Introduo ao SAS
141/200
procgplot;
title "Interaction plot for race & cancer ";
plot test * hasCancer = race;run;
quit;
procformat;
value race_f
8/2/2019 Introduo ao SAS
142/200
0 = "Black"
1 = "White";
value cancer_f
0 = "Healthy"
1 = "Sick";
run;
procgplot;
format race race_f. hasCancer cancer_f.;
title "Interaction plot for race & cancer ";
plot test * hasCancer = race / haxis = 0 to 1;
run;quit;
8/2/2019 Introduo ao SAS
143/200
Graphic Size
8/2/2019 Introduo ao SAS
144/200
You can set the horizontal and verticalsize in inches (in), centimeters (cm) orpoints (pt) of your pictures by using the
hsize= and vsize= graphics options.goptions hsize=4 in vsize=4 in;
If you are exporting images you can also
set xpixels= and ypixels=.
ODS Graphics
8/2/2019 Introduo ao SAS
145/200
SAS 9.1.x introduced new automatic graphics.These graphical procedures are still consideredexperimental so double check them.
Most of the commonly use analysis proceduresnow support these graphics. These include:corr, anova, glm, lifetest, logistic, mixed, phreg,reg.
Before you analysis code type ods graphics on;and after type ods graphics off;
The UNIVARIATE commandwith the HISTOGRAM statement
8/2/2019 Introduo ao SAS
146/200
with the HISTOGRAM statement
Coisas
8/2/2019 Introduo ao SAS
147/200
SAS Statements
8/2/2019 Introduo ao SAS
148/200
Global Statements DATA STEP Statements PROC STEP Statements
Outros tipos de Statement Macro Statements, SCL statements, etc.
8/2/2019 Introduo ao SAS
149/200
Global Statements
8/2/2019 Introduo ao SAS
150/200
Executado entreetapas Globals dentro de
etapas soexecutados antes daetapa
Often set global
parameters or options
Examples:endsas ;
filename fileref
path\file ;libname librefpath\file ;
options pageno=1 ;
page ;titlen text ;
X command ;
SAS DATA STEP Statements
8/2/2019 Introduo ao SAS
151/200
Declarations Executables May be restricted as
to location
data MYDATA ;length a $14 ;
input a ;
cards ;(847)-390-6660
(800)-SAS-HELP
;run;
Proc STEP Statements
8/2/2019 Introduo ao SAS
152/200
Proc Step Statementsavailable dependupon the PROC
Similar to Data StepStatements
title ImportantPhone Numbers ;
proc print
data=MYDATA ;
by a ;id a ;
run ;
Useful System Options
8/2/2019 Introduo ao SAS
153/200
Use the Optionsstatement to setvarious SystemOptions
OPTIONS option1=valueoption2 nooption3 ;
OPTIONSaltlog=filename
altprint= fname
nodate missing= stimer pageno=1
pagesize=60 ;
Formats and Informats
8/2/2019 Introduo ao SAS
154/200
Formats Converts character or
numeric data to aformatted text string
$UPCASEBESTw.
DOLLARw.d
MMDDYY8.
Informats Converts a formatted
text string to data$QUOTE
COMMA8.3
MMDDYY6.
Format & Informat Examples
8/2/2019 Introduo ao SAS
155/200
Formatdata _null_ ;pi=3.141592654 ;
p=put(pi,best5.) ;
put pi= p ;
stop ;
run ;
output: pi=3.142
Informatdata mydata ;
input date mmddyy8. ;
cards;
01/01/60
;
run ;
result: date=0
Funes
8/2/2019 Introduo ao SAS
156/200
Used in data stepprogramming Return character or
numeric values Syntax:function(arg1,...)
Examplesd=input(12/01/99,mm
ddyy8.)
y=abs(x)
TRANSFORMAO NOS DADOS
8/2/2019 Introduo ao SAS
157/200
Modificao de Variveis LidasData Arq;Input Nome $ 1-10 Sexo $ 12
Idade 14-15 Altura 17-18 Peso 20-22 ;Peso = Peso * 0.45 ;Cards ;
linha de dadosProc Print ;
Criao de Variveis Novas
8/2/2019 Introduo ao SAS
158/200
Data arq ;input nome $ 1-10 sexo 12 idade 14-15
altura 17-18 peso 20-22;Pesokg = peso * 0.45 ;
alturape = altura / 12 ;cards ;
linhas de dados
Proc print ;
Operadores Aritmticos e FunesPara montar expresses matemticas num programa
SAS di d d
8/2/2019 Introduo ao SAS
159/200
SAS, dispe-se dos operadores:
FUNES MATEMTICAS.Exemplos: Y = SIN(X)
Z = LOG(A+B)W = SQRT(A)+C
Smbolo Operao Exemplo Comando SAS
+ Soma R = S+T R = S+T
- Subtrao U = V-X U = V-X
* Multiplicao A = B*C A = B*C
/ Diviso G = H/I G = H/I
** Exponenciao Y = X 2 Y = X**2
COMANDO IF
8/2/2019 Introduo ao SAS
160/200
IF condio THEN comando 1 ; ELSE comando 2 ;
IF Altura > 72 THEN VX = 1 ; ELSE VX = 2 ; IF Idade < 13 Then VY = 0 ;
IF A >= 5 and B=0 THEN Result = 'SIM' ; ELSE Result = 'NAO' ;
OPERADORES LGICOS
8/2/2019 Introduo ao SAS
161/200
Smbolo Abreviao Comparao
< LT menor que GT maior que>= GE maior ou igual= EQ igual a-= NE diferente de
IF Sexo EQ 'F' THEN A = 1 ;
OU
IF Sexo = 'F' THEN A = 1 ;
The DATA STEP Overview
8/2/2019 Introduo ao SAS
162/200
Data Step a feijocom arroz daprogramao SAS
DATA STEP compilado e depoisexecutado
DATA STEP um
loop de fazer at notem mais dados
Data Step Simples
8/2/2019 Introduo ao SAS
163/200
data mydata ;input expense ;
total+expense ;
cards;
12.005.95
16.28
13.42
;run ;
DATA STEP Compilao
8/2/2019 Introduo ao SAS
164/200
Compiles SASstatements Creates an input
buffer if necessary
initializes the programdata vector records SAS data set
descriptor information
8/2/2019 Introduo ao SAS
165/200
DATA STEP Execuo
8/2/2019 Introduo ao SAS
166/200
Counts iterations(increments _N_) Sets PDV values to
missing, Exceptions: Retained variables When reading a SAS
data set
8/2/2019 Introduo ao SAS
167/200
8/2/2019 Introduo ao SAS
168/200
Executing the DATA STEP (II)
8/2/2019 Introduo ao SAS
169/200
data mydata ;
input expense ;
total+expense ;
cards;
12.00
5.95
16.28
13.42
;
run ;
Input Buffer12.00
Program Data Vector:_N_ _ERROR_ expense total
1 0 12.0 .
DATA STEP Execution (III)
8/2/2019 Introduo ao SAS
170/200
Additional DATASTEP statements areexecuted operatingon the PDV
The PDV is written tothe SAS data set asan observation
Return to the top
Executing the DATA STEP (III)
8/2/2019 Introduo ao SAS
171/200
data mydata ;
input expense ;
total+expense ;
cards;
12.00
5.95
16.28
13.42
;
run ;
Program Data Vector:_N_ _ERROR_ expense total1 0 12.0 12.0
Output to MYDATA12.0 12.0
Putting it all together
8/2/2019 Introduo ao SAS
172/200
data mydata ;
input expense ;
total+expense ;
cards;
12.00
5.95
16.28
13.42
;
run ;
Program Data Vector:_N_ _ERROR_ expense total___ _______ _______ _____
d d R
Output to MYDATA_N_ expense total
1 12.0 12.0
2 _______ _____
3 _______ _____
4 _______ _____
Data STEP Compilao
8/2/2019 Introduo ao SAS
173/200
Input Buffer Used with input from a file, cards, etc, not with
SAS data sets
defaults to 200 characters Holds character data for parsing into theprogram data vector
Data Step Compilation
8/2/2019 Introduo ao SAS
174/200
Program Data Vector Buffer for the current observation All Statements are executed on data in the
Program Data Vector Written out as an observation at the end ofeach iteration
Data Step Compilation
8/2/2019 Introduo ao SAS
175/200
DATA SET Descriptor information Variables and data types/sizes Informats Formats Labels indexed variables Number of observations
Last Modified
Execution (PDV Initialization)
8/2/2019 Introduo ao SAS
176/200
SAS Resets PDV (program data vector)values to missing at the top of the DATASTEP except when
A variable is listed in a retain statement A variable is in an implied retain Data is read in from a SAS data set, e.g. aset statement is used
Execution (Reading in Data)
8/2/2019 Introduo ao SAS
177/200
Data Sources Instream Data SAS Data Sets External Files
Instreamcards ;
cards4 ;
SAS Data Setsset olddata ;
External filesinfile myfile...;
input x...;
Execution (Reading in Data)
8/2/2019 Introduo ao SAS
178/200
Flat Files List Input Column Input Formatted Input
Named Input List Inputinput x y z ;...
12.7 16.5 13.2
Column Inputinput S $ 1-5 a 6-9SKU02123
Formatted Input
input date MMDDYY8.12/31/99
Named Inputinput name=$ score=
name=John score=100
Execution (Reading in Data)
8/2/2019 Introduo ao SAS
179/200
Infile Statement Sets the input file options
Missover Stopover
Firstobs obs pad Delimiter
Input Statement reads in data pointer controls
@n, +n, / #n n-n
other terms variable names
$ ~ = ? informat
8/2/2019 Introduo ao SAS
180/200
Execution (Programming)
8/2/2019 Introduo ao SAS
181/200
Data Step Code Looks a lot like otherlanguages Code operates on the variable values in
the program data vector The data step is a loop Functions, Logic and Flow control
Execution (Output)
8/2/2019 Introduo ao SAS
182/200
Keep and Drop determine which variablesin the Program Data Vector are written tothe data set
An output ; statement writes data to theSAS data set
If a data step does not contain an outputstatement it is implied at the end of the
data step
Using Data Steps
8/2/2019 Introduo ao SAS
183/200
To read in data from aflat file and preparefor processing
To write formatted
output to a flat file To perform custom
calculations on data
data NEWDATA ;... run ;
data _NULL_ ; ...put @1 ... run ;
data NEWDATA ;
set OLDDATA ;...
SAS Programming Tips
8/2/2019 Introduo ao SAS
184/200
Comments Indentation & Spacing Avoiding the missing semicolon ;
Beware the unbalanced quote Always read your log The Data Step Debugger
Comments
8/2/2019 Introduo ao SAS
185/200
Three types ofComments Comment Comment Statement
Macro Comment
/* Comment */
* Comment Statement ;
%* Macro Comment ;
Comments can gobetween tokens, butcannot be nested
Comment statements
must go betweenstatements
Macro comments are
stripped during macroprocessing
Avoid Missing Semicolons
8/2/2019 Introduo ao SAS
186/200
SAS statements end with a semicolon The missing semicolon is probably the
most common SAS error
Avoid the missing semicolon by putting aspace before it:data mydata ;
Beware the unbalance quote!
8/2/2019 Introduo ao SAS
187/200
Unbalanced quotes can kill you. Sometimes its just easier to start over So save your work often
Use quotes consistently Double check statements with quotes string literal ¯ovar
or
The Data Step Debugger
8/2/2019 Introduo ao SAS
188/200
data baddata/debug ;
statements ;
...
run ;
Use the data stepdebugger ininteractive/displaymanager mode
Create watchvariables, and stepthrough data stepcode
Best with small datasets
Always read your log
8/2/2019 Introduo ao SAS
189/200
Always read your log Always read your log Always read your log
Always read your log Always read your log Always read your log Always read your log
Libraries & Catalogs
8/2/2019 Introduo ao SAS
190/200
Libraries logical collections of
SAS stuff
Usually a directory Permanent and
Temporarye.g. work.data
libname mylibc:\path\dir\ ;
Catalogs Catalogs contain
compiled SAS stuff
(entries) Catalogs are storedin libraries
SAS code, Macro
code, AF & SCLcode, etc. Graphs, Formats
Saving code
8/2/2019 Introduo ao SAS
191/200
Name the contents of the Editor window currently blank
Select the editor window
Choose FileSave as X:\brownbag.sas
Save regularly
Consistent indentation &spacing
8/2/2019 Introduo ao SAS
192/200
Properly indent andclose out each dataand proc step
Use indentation for do
loops, conditionalprocessing, etc.
Be liberal with white
space
The first thing Ialways do when Imgiven old legacy codeis properly indent the
code.Once this is done, theproblem is usuallyself-evident.
8/2/2019 Introduo ao SAS
193/200
VII. Reducing repeated code
Macros
A very brief introduction to theSAS Macro facility
8/2/2019 Introduo ao SAS
194/200
The Macro facility is a tool for writing SAScode. All it does is process text
Macros resolve first then code is sent tothe compiler Similar to the C preprocessor
Macros
8/2/2019 Introduo ao SAS
195/200
Often you need to repeat analyses with minor adjustments
Instead of cutting and pasting
use a macro
Macros
8/2/2019 Introduo ao SAS
196/200
Basic structure%macro choose_a_name(arg1=,arg2=);
/* SAS code using &arg1, &arg2 */%mend;
Macros Dont say
8/2/2019 Introduo ao SAS
197/200
Instead, say
SAS Macro Variables
8/2/2019 Introduo ao SAS
198/200
&foo or &bar. Assignment %let foo=string literal ; Up to 64K
Macro Variable Arrays &&var&i Macro Variable References &&&foo Global or Local
Macro Functions
8/2/2019 Introduo ao SAS
199/200
Declaration%macro mymacro(data=&data) ;macro statements ;
...%mend mymacro ;
Macro Call
%macro(mydata)
Para aprender mais
8/2/2019 Introduo ao SAS
200/200
Online documentation wks.uts.ohio-state.edu/sasdoc/8/sashtml/onldoc.htm very technical
The Little SAS Book in SRL, great introduction & reference
Slides J. Patrick McDonald Spikeware
Don Miller