Professional Documents
Culture Documents
Introduo ao SAS/ produtos do SAS SAS Fundamentals Data Step Proc Steps Informaes sobre programao em SAS SAS Macro
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
Statistical Analysis System, Desenvolvido em 1970s na North Carolina State University SAS Institute Inc. formado em 1976 Software de estatstica mais usado em industria e universidades
SAS windows
escolha WindowTile Horizontally
Type code
Ajuda
Nova janela
Explorer Window
Log Window
Salvar
Editor
Editor Window tem os dados e programas de SAS
Explorer
Explorer Window
Libraries Folder
Contedo do Work Folder So conjuntos de dados criados no SAS Via inputting dados e Via criando conjuntos de dados Usando programas de SAS
Log Window
Log Window tem um relatrio de Todos os comandos submitidos para SAS e mostra erros
Output Window
Output Window tem output baseado em programas de SAS programs submitido no Editor Window.
Results Window
The Results Window mostra uma listagem dos programas de SAS submitido na ordem de submisso Click on any procedure to view all output parts of the procedure and click on any individual part to view the actual output.
SAS Help
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
Data Set
Descritor: Nomes das variveis, Labels, Tipos de dados, formatos etc Var Nome data idade altura peso Obs1 Obs2
Processamento
SAS System compila e depois exceuta cada step em sequencia Limite de step marcado por RUN; As vezes QUIT; ou o inicio da proxima step data MYDATA ; SAS Statements ; ... run ; proc print data=MYDATA ; run ;
Step-at-a-time Processing
SAS System Compila e depois executa cada etapa em sequencia O limite da etapa marcada por RUN; As vezes QUIT; ou o inicio da proxima etapa data MYDATA ; SAS Statements ; ... run ; proc print data=MYDATA ; run ;
Basic structure DATA datasetname; ; Each statement ends with a semicolon; RUN; INPUT describes the format
character variables followed by $ DATALINES introduces the data. /* comments enclosed */
Submitting code
Highlight and submit code
(A word on PROCEDURES)
Basic structure PROC procedure DATA=dataset; ; RUN; Each statement ends with a semicolon; E.g., PROC print DATA=MissAmericas; RUN;
IMPORT figures out the variable types (numeric, character, etc.) and takes variable names (Year, Name, etc.) from the first row.
Data file: Missamericas Library: Work (default) Work is a temporary folder on some disk
erased when you quit SAS
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.sas7bdat on the X: drive?
Saving code
Name the contents of the Editor window
currently blank
Save regularly
V. Analysis
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
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 ;
Proc Compare
Used to compare one data set to another Very flexible Useful when developing code
proc compare <options> data=onedata compare=two ; var variablelist ; out=compdata ; run ;
Proc Contents
Provides information about a SAS data set proc contents data=mydata ; run ;
-----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
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;
Proc Datasets
Library contents maintenance copy data sets delete data sets index data sets etc. proc datasets library=libref ; delete mydata ; run ; quit ;
Proc Format
Use proc format to create custom formats and informats This is a powerful technique for transforming custom data proc format ; value agefmt low-12=child 13-19=teen 20-high=adult ; run ;
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 ; 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 ;
Proc Sort
Sorts data by the listed variable Sorted data is necessary for merging and other by group processing proc sort data=mydata out=sorted; by sortvar ; run ;
Proc SQL
An excellent tool for beginning SAS coders who are experienced with SQL Great tool for use with SAS/Access to pull data from Oracle, DB2, etc. proc sql ; sql statemnts ; quit ;
Proc Transpose
What to use when rows is columns and columns is rows? Transpose! proc transpose data=mydata ; by varlist ; copy varlist ; run ;
Proc Corr
Computes Correlation proc corr data=mydata ; Coefficients between variables run ; Spearman, and Kendall, and Pearson, Oh-my!
Proc Freq
Counts data frequencies, prepares cross-tabulation tables and calculates descriptive statistics proc freq data=mydata ; tables var1*var2 ; run ;
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 ;
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 ;
Proc Means
Calculates statistics
N, NMISS, MIN, MAX, RANGE, SUM, SUMWGT, MEAN, USS (soma dos quadrados no corrigida), CSS (corrigida), VAR, STD (desvio padro), STDERR (erro padro), CV, SKEWNESS, KURTOSIS, T, PRT
N, NMISS, MEAN, STD, MIN, MAX, RANGE, SUM, VAR, USS, CSS, STDERR, CV, SKEWNESS, KURTOSIS, T, PRT, SUMWGT.
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' ;
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 ;
Proc Rank
Creates ranks for numeric data in a SAS data set proc rank data=mydata ; by varlist ; ranks newlist ; run ;
Proc Tabulate
Prints descriptive statistics Does not create a output SAS data set proc tabulate data=mydata ; var varlist ; table <<pg>,row>,col ; run ;
DATA REGR; INPUT ANO Y X1 X2 @@; CARDS; . . . PROC REG; MODEL Y=X1 X2;
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 ;
Proc ANOVA
EFEITOS A: EFEITO DE A A*B : INTERAO A(B): A DENTRO DE B A|B|C: TODOS OS EFEITOS PRINCIPAIS E CRUZADOS
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, POR TRATAMENTO E POR BLOCO.
Parcelas subdivididas
4 parcelas (variedades), 4 subparcelas (tratamento de sementes) 4 blocos (BANZATTO & KRONKA, 1989, p179)
VARIEDADES (A) TRATAMENTOS DE SEMENTES (B) B1 B2 B3 B4 B1 B2 B3 B4 B1 B2 B3 B4 B1 B2 B3 B4 1 42.9 53.8 49.5 44.4 53.3 57.6 49.8 64.1 62.3 63.4 64.5 63.6 75.4 70.3 68.8 71.6 BLOCOS 2 41.6 58.5 53.8 41.8 69.6 69.6 65.8 57.4 58.5 50.4 46.1 56.1 65.6 67.3 65.3 69.4 3 28.9 43.9 40.7 28.3 45.4 42.4 41.4 44.1 44.6 45.0 62.6 52.7 54.0 57.6 45.6 56.6 4 30.8 46.3 39.4 34.7 35.1 51.9 45.4 51.6 50.3 46.7 50.3 51.8 52.7 58.5 51.0 47.4
A1
A2
A3
A4
ARQUIVO DE DADOS
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.9 53.8 49.5 44.4 53.3 57.6 49.8 64.1 62.3 63.4 64.5 63.6 75.4 70.3 68.8 71.6 41.6 58.5 53.8 41.8 69.6 69.6 65.8 57.4 58.5 50.4 46.1 56.1 65.6 67.3 65.3 69.4 28.9 43.9 40.7 28.3 45.4 42.4 41.4 44.1 44.6 45.0 62.6 52.7 54.0 57.6 45.6 56.6 30.8 46.3 39.4 34.7 35.1 51.9 45.4 51.6 50.3 46.7 50.3 51.8 52.7 58.5 51.0 47.4
PROC GLM
DATA TESTE5; INPUT REPR RAO Y; CARDS; 115 116 122 123 212 213 215 216 217 228 228 229 313 324 324 326 326 327 ; TITLE " EXEMPLO 5 CURSO SAS "; PROC PRINT DATA = TESTE5; PROC GLM; CLASS REPR RAO; MODEL Y = REPR RAO; MEANS REPR RAO/DUNCAN;
DATA TEST6 INPUT REPR RAO Y CARDS; 115 116 122 123 212 213 215 216 217 228 228 229 313 324 324 324 326 326 327 ; 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;
7 6 4 3
DATA TESTE7; INPUT TRAT W Y ; CARDS; 153 195 1 11 6 132 245 276 202 287 2 10 8 223 2 12 9 258 387 376 334 323 386 324 ; TITLE "EXEMPLO 7 DO SAS"; PROC PRINT DATA = TESTE7; PROC GLM; CLASS TRAT; MODEL Y = TRAT W ; RUN;
IV. Graphics
PROC GPLOT
PROC GPLOT
PROC GPLOT
PROC GPLOT
PROC GPLOT
PROC GPLOT
PROC GHART
PROC GHART
PROC GHART
PROC GHART
PROC GHART
Proc Gchart
If you need to make bar charts, use proc gchart. Use can use axis options like in gplot and the pattern global option to set the bar fill colors and patterns. If your plotting variable is categorical you get one bar per value. If you are plotting a continuous variable the procedure will group the data for you; unless you tell it otherwise. pattern1 color = blue; Don't group proc gchart; vbar boys /discrete; run;
Proc Gchart(2)
Notice that the default statistic for vbar is frequency. Additional statistics you can request include cfreq (cumulative frequency), cpercent (cumulative percent), and percent. You can get these by including this on the vbar line: / type= statisticName proc gchart; vbar month ; run;
Proc Gchart(3)
You can tell it how many groups you want like this: proc gchart; vbar month /levels = 4; run; quit;
Proc Gchart(6)
You can specify two different statistics one to appear just above or below the bars:
proc gchart; format month season.; vbar month/outside=cfreq inside=freq; run; quit;
Basic HBAR
If you do a hbar you get frequency, cumulative frequency, percent, and cumulative percent information by default. If you want a different statistic just include it after the / If you dont want statistics include / nostats proc gchart; hbar boys /discrete; run;
Filling in Colors
On the chart line you can specify fill = x to use cross hatched fill patterns or fill = s for solid fill colors. Use solid colors if possible. You can set how patterns are applied by using patternid = on the chart line. Patternid can take these values by, group, midpoint, subgroup. Midpoint gives you a different pattern for each bar (or pie slice). Avoid using more than 9 different color/pattern combinations.
SEX Ma l e
F e ma l e
Co d e # 1 Ov a r y 2 Br e a s t 3 Ut e r u s / E n d o 4 Ce r v i x 5 Bl a d d e r 6 I nt est i ne 7 Pr o s t a t e 8 B o n e / S a r c o ma 9 CNS 1 0 F e ma l e NOS 1 2 Ma l e NOS 1 3 He a d & Ne c k 1 4 Ki d n e y 1 5 L e u k e mi a 16 Li ver 17 Lung 1 8 L y mp h o ma / My e l o ma 1 9 Ot h e r , NOS 2 0 Ot h e r - S p e c i f i e d 2 1 Pa n c r e a s 2 2 Sk i n 2 3 S t o ma c h / E s o p h 24 Thy r oi d 2 5 Ur i n a r y NOS 2 6 Pe r i t o n e u m 5 0 Oo p h o r e c t o my - P r o p h 5 2 Hy s t e r e c t o my 5 3 Ma s t e c t o my 5 4 Oo p h o r e c t o my - Ot h e r 5 5 B r e a s t Di s e a - B e n i g n 9 6 Me n t a l Re t a r d a t i o n 9 7 Ov a r i a n Cy s t 9 8 Ov a r i a n T u mo r - B e n i g 9 9 Un k n o wn 1 Ov a r y 2 Br e a s t 3 Ut e r u s / E n d o 4 Ce r v i x 5 Bl a d d e r 6 I nt est i ne 7 Pr o s t a t e 8 B o n e / S a r c o ma 9 CNS 1 0 F e ma l e NOS 1 2 Ma l e NOS 1 3 He a d & Ne c k 1 4 Ki d n e y 1 5 L e u k e mi a 16 Li ver 17 Lung 1 8 L y mp h o ma / My e l o ma 1 9 Ot h e r , NOS 2 0 Ot h e r - S p e c i f i e d 2 1 Pa n c r e a s 2 2 Sk i n 2 3 S t o ma c h / E s o p h 24 Thy r oi d 2 5 Ur i n a r y NOS 2 6 Pe r i t o n e u m 5 0 Oo p h o r e c t o my - P r o p h 5 2 Hy s t e r e c t o my 5 3 Ma s t e c t o my 5 4 Oo p h o r e c t o my - Ot h e r 5 5 B r e a s t Di s e a - B e n i g n 9 6 Me n t a l Re t a r d a t i o n 9 7 Ov a r i a n Cy s t 9 8 Ov a r i a n T u mo r - B e n i g 9 9 Un k n o wn 0 20 40 60 80 100 120 140 160 180
Ca n c e r
Si t e
as
F RE Q.
CUM. F RE Q.
P CT .
CUM. P CT .
F RE QUE NCY
F RE QUE NCY 180 170 160 150 140 130 120 110 100 90 80 70 60 50 40 30 20 10 0 1 2 3 4 56 7 8 9 11 1 1 02 3 4 OB UCBI P B C v r t e l n r o N F MH K a e e r at o n Sea e i r a r v d e s e ml a d y s u i ds t / ae d n t s x et a S l e / r i t a eN&y E n e r O n e c NS N d o O e o m S c a k 1 1 11 1 2 2 22 2 2 2 55 5 5 5 9 99 9 5 6 78 9 0 1 23 4 5 6 02 3 4 5 6 78 9 L L e i u v k e e r m i a L u n g L OOP y t t a mh h n p e e c h r r r o , - e m Sa a Np s / Oe MS c y i e f l i o e m d a SS T k t h i o y n mr a o c i h d / E s o p h U P OH M O B M OO U r e oy a o r e v v n i r ps s p e n aa k n i ht t h a t r r n a t oe e o s a i i o r o r r c r t l aa w y n ee t e nn n e c c o c DR N u t t mt i e CT O mo o y o s t y u S mm m e a s m y y y a r t o - - d r P OB a r t e t B o h n i e p e i o n h r g n i n g 1 2 34 5 6 7 89 1 1 1 1 0 2 3 4 OB UC B I P B C v r t e l n r o N F MH K a e er a t o nSe a e i r a r v d e s e ml a d y s ui d s t / a e d n t s x e t a S l e / r i t a e N&y E n e r O n e c NSN d o O e o m S c a k 11 1 1 1 22 2 2 2 22 5 5 5 5 59 9 9 9 56 7 8 9 01 2 3 4 56 0 2 3 4 56 7 8 9 LL ei uv k e er m i a L u n g L O OP y t t a mh h n p e ec h r r r o , - e m Sa a Nps / Oe MS c y i e f l i o e m d a S k i n ST t h o y mr a o c i h d / E s o p h UP O H MO B MO O U r e o y a o r e v v n i r p s s p en a a k ni h t t h at r r n at o e e o sa i i o r o r r c r t l a a w y n e e t e n n n e c c o c DR Nu t t mt i e C T Om o o y o s t y u S mm me a s m y y y ar t o - - d r P OBa r t et B o h ni e p e i o n h r gn i n g SEX Ca n c e r Si t e as Co d e #
Ma l e
F e ma l e
A GE 9 9 :
F RE Q. 1 65 80 67 77 76 93 71 91 70 67 113 98 85 72 78 94 91 73 63 48 65 60 62 45 40 76 45 55 49 31
CUM. F RE Q. 1 66 146 213 290 366 459 530 621 691 758 871 969 1054 1126 1204 1298 1389 1462 1525 1573 1638 1698 1760 1805 1845 1921 1966 2021 2070 2101
P CT . 0. 05 3. 09 3. 81 3. 19 3. 66 3. 62 4. 43 3. 38 4. 33 3. 33 3. 19 5. 38 4. 66 4. 05 3. 43 3. 71 4. 47 4. 33 3. 47 3. 00 2. 28 3. 09 2. 86 2. 95 2. 14 1. 90 3. 62 2. 14 2. 62 2. 33 1. 48
CUM. P CT . 0. 05 3. 14 6. 95 10. 14 13. 80 17. 42 21. 85 25. 23 29. 56 32. 89 36. 08 41. 46 46. 12 50. 17 53. 59 57. 31 61. 78 66. 11 69. 59 72. 58 74. 87 77. 96 80. 82 83. 77 85. 91 87. 82 91. 43 93. 57 96. 19 98. 52 100. 00
CUM. F RE Q. 1 66 146 213 290 366 459 530 621 691 758 871 969 1054 1126 1204 1298 1389 1462 1525 1573 1638 1698 1760 1805 1845 1921 1966 2021 2070 2101
P CT . 0. 05 3. 09 3. 81 3. 19 3. 66 3. 62 4. 43 3. 38 4. 33 3. 33 3. 19 5. 38 4. 66 4. 05 3. 43 3. 71 4. 47 4. 33 3. 47 3. 00 2. 28 3. 09 2. 86 2. 95 2. 14 1. 90 3. 62 2. 14 2. 62 2. 33 1. 48
CUM. P CT . 0. 05 3. 14 6. 95 10. 14 13. 80 17. 42 21. 85 25. 23 29. 56 32. 89 36. 08 41. 46 46. 12 50. 17 53. 59 57. 31 61. 78 66. 11 69. 59 72. 58 74. 87 77. 96 80. 82 83. 77 85. 91 87. 82 91. 43 93. 57 96. 19 98. 52 100. 00
Bad charts.
SAS will also let you specify subgroups (to give stacked subgroups). Do not do these graphics. People are bad at untangling the relative heights. 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
You can get simple scatter plots out of the analysis procedure proc reg. For fancy plots use proc gchart.
You can get great looking scatter plots with proc gplot.
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 0 1 1 1 0 6 2 ; run; proc gplot;
2 1 0 0
The Font
If you do not like the default font you change it with the graphic global option ftext .. goptions ftext='Verdana'; ... or you can specify a different font for different parts of the graphic. I will show this later.
kids 6
0 1 2 3 4 5 6 month 7 8 9 10 11 12
Symbols
You can change the plot symbols by setting a goptions option.
symbol1 value=star; proc gplot; plot kids * month; run; quit;
From SAS OnLineDoc V8. Copyright (c) 1999 SAS Institute Inc., Cary, NC, USA. All rights reserved.
Adding Markers
There is a SAS font called marker that has symbols. Set the font and use the single letters below to add in a symbol.
From SAS OnLineDoc V8. Copyright (c) 1999 SAS Institute Inc., Cary, NC, USA. All rights reserved.
Symbols
You can use custom symbols like this: symbol1 font=marker value= N color=red height = 3; This letter was proc gplot; chosen from the plot kids * month; previous slide. Note that it is a capital run; letter and it is not in quotes. quit;
Reset Symbols
To reset an option, follow it by an equal sign symbol1 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 name followed by a semicolon; symbol1; To reset all symbols type this: goptions reset=symbol;
Two Symbols
You can overlay two plots and use different symbols 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 ; proc gplot; plot boys * month girls * month/overlay; run; quit;
Axis options
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'); proc gplot; label Month = "Birth Month"; Use the custom axis. plot boys * month girls * month/overlay haxis = axis1; run;quit;
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; axis1 order = (1 to 12 by 1) label = (height=5pct font='Times New Roman') width = 3 major = (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 = 3 Set from 1 to 5 not 0 to 5 major = (Width = 3) minor = none value = (height = 5pct f='Times New Roman'); proc gplot; label Month = "Birth Month"; label boys = "Kids"; plot boys * month girls * month/overlay haxis = axis1 vaxis = axis2; run;quit;
Exporting Images
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 changing the appearance of the picture) include this code before 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
You can save your images in a SAS graphics catalog in a permanent library by including: gout=theLibname.theCatalogName on the proc gplot line. If you dont specify an output catalog your pictures will be saved in the work library in a catalog called Gseg. If the graphics catalog exists the new graphics will be added to it. If does not exist, it will be created for you. You can use the SAS explorer to look at files in a graphics catalog.
Interaction plot
data blah; input hasCancer race test; datalines; 0 0 6.8 0 1 5.8 1 0 6.4 1 1 9.3 ; run;
symbol1 interpol = join color = black; symbol2 i = join color = red; proc gplot; title "Interaction plot for race & cancer "; plot test * hasCancer = race; run; quit;
proc format; value race_f 0 = "Black" 1 = "White"; value cancer_f 0 = "Healthy" 1 = "Sick"; run; proc gplot; format race race_f. hasCancer cancer_f.; title "Interaction plot for race & cancer "; plot test * hasCancer = race / haxis = 0 to 1; run; quit;
Graphic Size
You can set the horizontal and vertical size in inches (in), centimeters (cm) or points (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
SAS 9.1.x introduced new automatic graphics. These graphical procedures are still considered experimental so double check them. Most of the commonly use analysis procedures now 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;
Coisas
SAS Statements
Global Statements DATA STEP Statements PROC STEP Statements Outros tipos de Statement
Macro Statements, SCL statements, etc.
SAS Statements
Pode comear com um LABEL seguido por um colon : Espao em branco ignorado Termina com semicolon ;
LABEL: Statement ; title 'obprogram' ; data hi ; Hello = 'World!' ; run ; proc print ; id hello ; run ;
Global Statements
Executado entre etapas Globals dentro de etapas so executados antes da etapa Often set global parameters or options
Examples:
endsas ; filename fileref path\file ; libname libref path\file ; options pageno=1 ; page ; titlen text ; X command ;
Informats
Converts a formatted text string to data $QUOTE COMMA8.3 MMDDYY6.
output: pi=3.142
result: date=0
Funes
Used in data step programming Return character or numeric values Syntax:
function(arg1,...)
Examples
d=input(12/01/99,mm ddyy8.) y=abs(x)
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 Funes Para montar expresses matemticas num programa SAS, dispe-se dos operadores:
Smbolo + * / ** Operao Soma Subtrao Multiplicao Diviso Exponenciao Exemplo R = S+T U = V-X A = B*C G = H/I Y=X2 Comando SAS R = S+T U = V-X A = B*C G = H/I Y = X**2
COMANDO IF
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
Smbolo < <= > >= = -= Abreviao LT LE GT GE EQ NE Comparao menor que menor ou igual maior que maior ou igual igual a diferente de
Checks syntax & compiles Creates input buffer (200 characters) PDV :
_N_ _ERROR_ expense total
Output to MYDATA
12.0 12.0
Output to MYDATA
_N_ 1 2 3 4 expense 12.0 _______ _______ _______ total 12.0 _____ _____ _____
Instream cards ; cards4 ; SAS Data Sets set olddata ; External files infile myfile...; input x...;
Column Input
input S $ 1-5 a 6-9 SKU02123
Formatted Input
input date MMDDYY8. 12/31/99
List Input
input x y z ;... 12.7 16.5 13.2
Named Input
input name=$ score= name=John score=100
Input Statement
reads in data pointer controls
@n, +n, / #n n-n
other terms
variable names $~=? informat
Execution (Programming)
Data Step Code Looks a lot like other languages Code operates on the variable values in the program data vector The data step is a loop Functions, Logic and Flow control
Execution (Output)
Keep and Drop determine which variables in the Program Data Vector are written to the data set An output ; statement writes data to the SAS data set If a data step does not contain an output statement it is implied at the end of the data step
Comments
Three types of Comments
Comment Comment Statement Macro Comment
/* Comment */ * Comment Statement ; %* Macro Comment ;
Comments can go between tokens, but cannot be nested Comment statements must go between statements Macro comments are stripped during macro processing
Catalogs
Catalogs contain compiled SAS stuff (entries) Catalogs are stored in libraries SAS code, Macro code, AF & SCL code, etc. Graphs, Formats
Saving code
Name the contents of the Editor window
currently blank
Save regularly
Macros
Often you need to repeat analyses
with minor adjustments
Macros
Basic structure %macro choose_a_name (arg1=, arg2=); /* SAS code using &arg1, &arg2 */ %mend;
Macros
Dont say
Instead, say
Macro Functions
Declaration
%macro mymacro(data=&data) ; macro statements ; ... %mend mymacro ;
Macro Call
%macro(mydata)
Slides