Sunteți pe pagina 1din 61

SAS

BASICO
Giampaolo Orlandoni M. M Josefa Ramoni P.

I tit t d Instituto de E Estadstica t d ti A Aplicada li d Universidad de Los Andes Venezuela l

INTRODUCCION AL SAS
1. 2. 3. 4 4. 5. 6 6. Estructura SAS Paso de Datos: Data Paso de Procedimientos: Proc Entrada de Datos: Input, Input Infile, Infile Import Formato de Datos: Lista, Columna, Formato Procedimientos: 1. Proc Print 2. Proc Sort 3. Proc Contents 7. Creacin de Archivos permanentes: Libname 8. Ejercicios

ESTRUCTURABASICA DEUN PROGRAMASAS

1. PASODEDATOS( (DATASTEP) ) 2 PASODEPROCEDIMIENTOS(PROCSTEP) 2.

1. PASODEDATOS( (DATASTEP) )
DATA nombre; INPUT variables numricas y caracteres; DATALINES; {datos} ; RUN;

1. PASODEDATOS(DATASTEP)
Data Venta; Inp t anio ventas Input entas costo costo; Datalines; 1991 12132 1100 1992 19823 1100 1993 16982 1200 1994 18432 1200 1995 19432 1200 ; Run;

2. PASODEPROCEDIMIENTO(PROCSTEP)
2.1 Proc Print data=venta; Title 'Reporte Reporte 1 1'; ; run; Proc Print data=venta; Var anio ventas; Title 'Reporte Reporte 2 2'; ; run; Proc P P Print i d data=venta; By costo; ; Var anio ventas; Title 'Reporte 3'; run;

2.2

2 3 2.3

FormaGeneraldePROCPRINT

Proc Print data= data set; Ti l ttulo'; Title l ' By run;

variables;

Var variables;

1_Ej1.sas

1-Leer 1 Leer los datos 2-Imprimir datos 3-Imprimir p Ao y Ventas, por Costo 4-Usar ttulos

Data venta; Input anio ventas costo; Datalines; ; 1991 12132 1100 1992 19823 1100 1993 16982 1200 1994 18432 1200 1995 19432 1200 ; run; Proc Print data=venta; title 'Reporte 1 '; run; Proc Print data=venta; Var anio ventas; title 'Reporte Reporte 2 '; ; run; Proc Print data=venta; y costo; ; By Var anio ventas; title 'Reporte 3 '; run;

1_Ej2.sas
1-Leer los datos 2-Calcular variable Beneficio 2-Imprimir datos 3 I 3-Imprimir i i A Ao, Ventas, Beneficio por Costo. Costo

Data venta; Input anio ventas costo; Datalines; 1991 12132 1100 1992 19823 1100 1993 16982 1200 1994 18432 1200 1995 19432 1200 ;

Beneficio = ventas - costo; ;

Proc Print data=venta; title 'Reporte 1 '; run; Proc Print data=venta; Var anio ventas beneficio; title 'Reporte Reporte 2 '; ; run; Proc Print data=venta; By costo; Var anio ventas beneficio; title 'Reporte 3 '; run;

1_Ej3.sas

Data venta; Input p an ventas costo; ; Ben = ventas - costo;


Datalines; 1991 12132 1992 19823 1993 16982 1994 18432 1995 19432 ; 1100 1100 1200 1200 1200

1-Leer los datos 2-Imprimir datos con Labels. 3-Calcular totales

Proc Print Data=venta Split='*'; Label ventas='Ventas * Ao costo='Costo ben='Beneficio antes *Impuesto'; Format ventas costo ben dollar10.1; Id an; Sum ventas costo ben; Title 'PRINT con Totales'; run;

PROC PRINT <DATA=SAS-data-set> <option(s)>;


Data= data SAS a procesar Double: output con doble espaciado Split= forma de separar encabezados columna Noobs N suprimir columna obs en el output imprimir N. obs al final del data set

BY variable(s); FOOTNOTE<n> <'footnote'>; FORMAT variable(s) format-name; ID variable(s); ( ); LABEL variable='label'; PAGEBY variable; SUM variable(s); ariable(s) SUMBY variable; TITLE<n> <'title'>; VAR variable(s); WHERE where-expression;

SUM variable(s): Identifies the numeric variables to total in the report. When also use the BY statement, the SUM statement produces subtotals each time the value of a BY variable changes. SUMBY variable: Limits the number of sums that appear in the report. PROC PRINT reports totals only when variable changes value or when any variable that is listed before it in the BY statement changes value value. Must use a BY statement with the SUMBY statement. WHERE where-expression: p Subsets the input data set by identifying certain conditions that each observation must meet before an observation b ti i available is il bl for f processing. i Where-expression defines the condition. The condition is a valid arithmetic or logical expression that generally consists of a sequence of operands and operators.

1_Ej2-1.sas
Qu sucede si hay algn dato faltante en alguna de las variables? Correr el programa con un dato faltante para el costo del ao 1993. Indicar al SAS que ese dato es faltante con (.) Efectos. 1993 16982

Data venta; Input anio ventas costo; Beneficio = ventas - costo; Datalines; 1991 12132 1100 1992 19823 1100 1993 16982 1994 18432 1200 1995 19432 1200 ; Proc Print data=venta; title 'Reporte 1 '; run; Proc Print data=venta; ; Var anio ventas beneficio; title 'Reporte 2 '; run; Proc Sort data=venta; by costo; run; Proc Print data=venta; By costo; Var anio ventas beneficio; title 'Reporte 3 '; run;

LecturadeDatos

1. Input 2. Infile 3 Import 3. I

1.

INPUT

Nombra las variables del conjunto de datos que q e el programa debe leer leer. Informa la ubicacin de los valores de las variables del conjunto de datos. Modos de lectura: 1. Input Lista: 2. Input Columna: 3. Input Formato: formato libre formato fijo informats

INPUT

Caractersticas FormatoLibre:datos q quenoestnencolumnas fijas.Estnseparadosporespaciosblancos Delimita loscamposconespaciosblancos ($) ) Leedatosnumricosocaracteres( Longitudnombre:8caracteres Leedatosfaltantesindicadosconpunto(.) Noleecaracteresconblancosintercalados Especificacindelinicioyfindelacolumnadela variable (datosencolumnasfijas) Especificalaposicindelacolumna luegodel nombredelavariable Leevariablescaracter,usando$luegodel nombredelavariable Permitedarinstruccionesespecficas: Informatname w.d wespecifica ifi ancho h d decampo( (opcional) i l) . delimitadorobligatorio ddgitosdecimales(opcional)

Modificadores
$ leecaracteres & leecaracterescon blancosintercalados :usaformatoyse detienealsiguiente espacioblanco

LISTA

COLUMNA

FORMATO

ApuntadorAbsoluto: @n:iralacolumnan ApuntadorRelativo: +n:avanzarn columnas

J P L A A

1 2 3 4 5 6 7 8

U E U L L

A D I F I

N R S R C

9 0 1 2 3 4 5

O A E D O I A

M M F M F

1 1 1 1 1

2 4 3 5 5

1 1 1 1 1

5 6 4 5 5

0 0 0 8 0

8 9 0

4 5 4 4 4

0 0 2 8 7

INPUT LISTA INPUT Nombre $

EJEMPLO Sexo $ Edad Altura Peso;

COLUMNA

INPUT Nombre $ 1-8 Sexo $ 11 Edad 13-14 Altura 16 16-18 18 Peso 20 20-21; 21;

FORMATO

INPUT Nombre $8. $8 @11 Sexo $1 $1. +1 Edad 2 2. +1 Altura 4. +1 Peso 3.;

Input Columna
Data nombres; INPUT Nombre $ 1-8 Sexo $ 11 Edad 13-14 Altura 16-18 Peso 20-21; datalines; juan m 12 150 40 pedro m 14 160 50 luisa f 13 140 42 alfredo m 15 158 48 alicia f 15 150 47 ; proc print; run;
C l Columna Obs 1 2 3 4 5 18 11 13 14 16-18 13-14 16 18 20-21 20 21 Nombre Sexo Edad Altura Peso juan j pedro luisa alfredo alicia m m f m f 12 14 13 15 15 150 160 140 158 150 40 50 42 48 47

MODIFICADORES @, @@ 1 Modificador @n: 1-Modificador


Ir a la columna Nmero n, , p para leer la variable indicada Permite leer variables en cualquier orden, saltar variables

2 Modificador @@ 2-Modificador
Permite seguir g leyendo y variables en un mismo registro Debe ser el ltimo elemento del INPUT.

Mltiples observaciones a partir de un registro de datos

Eldoble @@(doubletrailing@): Evita que leaunnuevo registro cuando encuentra unnuevo INPUT Evita que sesuelte elregistro cuando elprograma regresa alinicio del DATAstep. Ejemplo
Data Set Creado con @@:
Obs Sexo Obesidad 1 2 3 4 5 6 m f m f m m 13.3 22.0 22.0 23.2 16 0 16.0 12.0

Data obeso; I Input t Sexo S $ Obesidad Ob id d @@; datalines; m 13.3 f 22 m 22 f 23.2 m 16 m 12 ; proc print data=obeso; run;

2.

INFILE
Permite leer archivos de datos externo, en formato ASCII. Se ubica entre las sentencias DATA e INPUT:
Data nombre; INFILE c:\DataSAS\Archivo.dat; Input var1 var2 .... varn;

Opcin MISSOVER: asigna valor faltante a datos que no tienen el smbolo (.)
Data nombre; INFILE c:\DataSAS\Archivo.dat MISSOVER; Input I t var1 1 var2 2 .... varn;

2.

/* Definir archivos permanentes SAS; Uso de LIBNAME libname ventas 'c:\DataSas\dat'; ods html file= 'c:\DataSAS\html\1 c:\DataSAS\html\1_LibVenta.html LibVenta html'; ; data ventas.TR1; INFILE 'C:\DataSas\dat\tr1.dat'; Input Depart $ Lugar $ Trim Ventas; proc print; run; /* Dos formas de leer el archivo TR1 */ / / /* 1-Indicando el Path completo */ Proc print data= 'c:\DataSAS\dat\TR1'; Var Ventas; run;

INFILE

*/

/* 2-Usando el nombre asignado por libname */ proc print data=ventas.TR1; var a t trim lugar uga depa depart t ventas; e tas; run; u ; ods html close; ..\..\..\..\..\..\..\DataSAS\html\1_LibVenta.html /*Definir archivos permanentes SAS; LIBNAME */ libname ventas 'c:\DataSas\dat'; NOTA: Libref VENTAS was successfully assigned as follows: Engine: V9 Physical Name: c:\DataSas\dat

2.

INFILE con MISSOVER

ARCHIVO TR1.dat con dato faltante en la variable ventas. U Usar MISSOVER para l leer correctamente t t l los d datos. t Partes Partes Partes Repar Repar Repar Herram Herram Herram Sydney Atlanta Paris Sydney Atlanta Paris Sydney Atlanta Paris 1 1 1 1 1 1 1 1 1 4043.97 6225.26 3543.97 5592.82 9210.21 8591 98 8591.98 1775.74 5914.25

data ventas.TR1; INFILE 'C:\DataSas\dat\tr1.dat' MISSOVER; Input Depart $ Lugar $ Trim Ventas; proc print; run;

3. Proc IMPORT
Permite leer archivos de datos externo, en cualquier formato: ASCII, xls, dbf, csv. Se puede ejecutar por comandos: Archivo c o Importar po ta Datos atos PROC IMPORT statement arguments: g DATAFILE= OUT= DBMS= REPLACE Data source statements: DELIMITER= DELIMITER GETNAMES=

Proc IMPORT
proc import datafile= 'C:\DataSas\importarTab.dat' out=misDatosTab dbms=dlm replace; getnames yes; getnames=yes; run; proc print data=misDatosTab; run; ods html file="datosTab.html"; proc print; run; ; ods html close;
Obs 1 2 3 4 5 6 7 Region Sur Sur Sur Nor Nor Sur Nor Estado AZ BL BR MR FC AP AZ Mes JAN01 FEB01 FEB01 FEB01 MAR01 MAR01 MAR01 Gasto 2000 1200 8500 3000 6000 9800 1500 Ingreso 8000 6000 11000 4000 5000 13500 1000

Proc Sort:OrdenarDatos
PROC SORT <DATA=SAS-data-set>; BY variable(s);
PROC SORT DATA DATA=SAS-data-set: SAS data set: ordena un SAS DS segn los valores de variables listadas en el BY. BY variable(s): Especifica las variables por las que PROC

SORT ordena las observaciones del archivo. archivo PROC SORT ordena el DS en orden ascendente.

1_Ej4.sas Input Libre con variable caracter


Uso de Proc Sort Efecto de no usar Sort

Data venta; Input an mes $ ventas costo; Beneficio = ventas - costo; D t li Datalines; 1991 ene 12132 1200 1992 feb 19823 1100 1993 993 e ene e 16982 698 1200 00 1994 feb 18432 1100 1995 ene 19432 1200 ; run;

Proc Sort data=venta; By mes costo; run;

Proc Print data=venta; By mes; Var an ventas costo beneficio; titl 'Reporte title 'R t M Mes ' '; run; Proc Print data=venta; y mes costo; ; By Var an ventas beneficio; title 'Reporte Mes_Costo ; run;

1_Ej5.sas
Input Libre Variables caracteres Datos faltantes marcados con (.) Blancos intercalados Modificadores $: caracteres &: blancos intercalados

ods html file='c:\DataSas\Clase.html'; *Paso 1: Crear un archivo de datos SAS; Data clase; Input nombre $ sexo $ edad origen & $12.; *Paso 2:
datalines; alfredo alicia barbara henry lucia juan saul pablo luis

Lectura de observaciones;
M F F M F M M M M 14 14 14 15 15 16 16 15 16 Merida . Caracas Pto Cabello . Valencia Caracas Pto Cruz Merida

; p con los datos SAS; ; * Paso 3: Operar Proc Print; title 'Datos Clase'; run; Proc Sort; By sexo edad; run; Proc Print data=clase; By sexo edad; run; ods html close;

1_Ej6.sas
Lectura Matriz de C Correlacin l i

ods html file='c:\DataSas\1_Ej6.html'; DATA D1(TYPE D1(TYPE=CORR) CORR) ; INPUT _TYPE_ $ _NAME_ $ Datalines;
N STD CORR CORR CORR CORR CORR CORR CORR CORR CORR CORR CORR CORR ;

V1-V12;

. 300 300 300 300 300 300 300 300 300 300 300 300 . 2.48 2.39 2.58 3.12 2.80 3.14 2.92 2.50 2.10 2.14 1.83 2.26 V1 1.00 . . . . . . . . . . . V2 .69 1.00 . . . . . . . . . . V3 .60 60 .79 79 1 1.00 00 . . . . . . . . . V4 .62 .47 .48 1.00 . . . . . . . . V5 .03 .04 .16 .09 1.00 . . . . . . . V6 .05 -.04 .08 .05 .91 1.00 . . . . . . V7 .14 14 .05 05 .06 06 .12 12 .82 82 .89 89 1 1.00 00 . . . . . V8 .23 .13 .16 .21 .70 .72 .82 1.00 . . . . V9 -.17 -.07 -.04 -.05 -.33 -.26 -.38 -.45 1.00 . . . V10 -.10 -.08 .07 .15 -.16 -.20 -.27 -.34 .45 1.00 . . V11 -.24 24 -.19 19 -.26 26 -.28 28 -.43 43 -.37 37 -.53 53 -.57 57 .60 60 .22 22 1 1.00 00 . V12 -.11 -.07 .07 .08 -.10 -.13 -.23 -.31 .44 .60 .26 1.00

Proc Print; run; ods html close;

1_Ej7.sas

ods html file='c:\DataSas\1_Ej7.html'; DATA Ej7; INPUT @1 (V1-V6) (1.); D t li Datalines;


556754 567343 777222 66 2 3 665243 666665 353324 767153 666656 334333 567232 455323 455544 ; Proc Print; run;

Lectura de variables consecutivas

ods html close;

1_Ej8.sas
Lectura de un archivo dos veces, luego d una de condicin if Subconjunto de datos creado con el smbolo @

ods html file='c:\DataSas\1_Ej8.html'; DATA Ej8; INPUT equipo $ 13-16 @; IF equipo='rojo'; INPUT idn 1 1-4 4 pesoi 20 20-23 23 pesof 24 24-26; 26; redpeso=pesoi-pesof; Datalines; 1023 David rojo 189 165 1049 Amelia A li azul l 145 124 1219 Alan rojo 210 192 1246 Raul azul 194 177 1078 Alicia rojo j 127 118 1221 Juan azul 220 . ; Proc Print data=Ej8; run; PROC CORR DATA=Ej8 NOMISS; VAR pesoi pesof redpeso; run; ods html close;

1_Ej9.sas
Creacin de mltiples observaciones a partir ti d de un registro Data set creado con el smbolo @@

ods html file='c:\DataSas\1_Ej9.html'; DATA Ej9; INPUT sexo $ edad peso @@; Datalines; m 13 30 f 22 75 f 18 70 m 22 70 f 23 78 m 20 65 m 16 50 m 12 25 f 19 73 ; run; Proc Print; run; Proc Sort; By sexo; run; ; Proc print data=Ej9; By sexo; run; PROC CORR DATA=Ej9 NOMISS; VAR edad peso; run; ods html close;

ods html file='c:\DataSas\1_Ej10.html';

1_Ej10.sas

DATA Info; INPUT Nombre $15. $15 /Direccion $20. $20 /Ciudad_Estado Ciudad Estado $15. $15 /Zip $5 $5.; ; Datalines; Juan Sanchez Av Urdaneta Merida MR 05101 Luis Perez Av Rondon Barinas BR 02511

Uso del control t l apuntador/ Leer desde varios registros

Generar una observacin Jose Moreno

Calle Mario Porlamar NE 03356 ; run; Proc Print; title ' '; run; ods html close;

ARCHIVOS SAS PERMANENTES


Los nombres de archivos tienen dos niveles: Libref.Libname j p Ejemplo: Libname C 'C:\DataSAS\'; Data C.Ventas;
Libref: Declara la unidad y directorio de almacenamiento del conjunto de datos (Sas Data Set). En este caso es C:\DataSAS Libname: nombre de archivo. El Archivo Ventas se crea con la extensin *.SSD, y se almacena en la librera de referencia C (que hace referencia al directorio 'C:\DataSAS\) 'C \DataSAS\)

Librera de trabajo del Sas: C:\SAS\SASWORK Work.Ventas: archivo Ventas almacenado en Work

ARCHIVOS SAS PERMANENTES: HERRAMIENTAS

Con Herramientas se crea Nueva Librera y se indica: Nombre de la librera Ruta: direccin fsica de la librera

1_Ej11.sas

Libname C 'C:\DataSAS\'; ods html file='c:\DataSas\Lib3.html'; Data C.Ventas; I Input t Region R i $V Venta; t D t li Datalines;
R1 10 R3 20 R7 30 R2 40 R4 50 R6 60 R5 70 R1 30 R3 30 R7 50 R2 10 R4 80 R6 90 R5 50 R1 10 R3 20 R7 30 R2 40 R4 50 R6 60 R5 70 R1 30 R3 30 R7 50 R2 10 R4 80 R6 90 R5 50

Creacin de Archivos Permanentes Uso de Libname

; Proc Print; run; ods html close;

1_Ej12.sas

/* Crear archivo permanente SAS */ libname ventas 'c:\DataSas\Venta2002'; Data ventas.TR1; Input Depart $ Lugar $ Trim Datalines;
Partes Partes Partes Repar Repar Repar Herram Herram Herram Sydney Atlanta Paris Sydney Atlanta Paris Sydney Atlanta Paris 1 1 1 1 1 1 1 1 1 4043.97 6225.26 3543 97 3543.97 5592.82 9210.21 8591.98 1775.74 2424.19 5914.25

Ventas;

Creacin de archivo hi permanente Libname

/* Dos formas de leer el archivo TR1 */ /* 1-Indicando el Path completo */ Proc means data= 'c:\DataSAS\Venta2002\TR1'; Var Ventas; run; /* 2-Usando el nombre asignado por libname */ Proc Print data=ventas.TR1; var trim lugar depart ventas; run; Proc means data= ventas.TR1; Var Ventas; run;

1_Ej12.sas Libname

Libname C 'C:\DataSAS\'; ods html file file='c:\DataSas\VentaLib3 c:\DataSas\VentaLib3.html html'; ; Proc Sort Data= C.Ventas By y Region; g ; Data C.Totales(Keep=Region Total); Set C.VentasOrd; By Region; If First.Region then Total=0; Total+Venta; If Last.Region; Proc Print Data=C.Totales Noobs; Title 'Total Ventas 2000'; run; ods html close; Out=C.VentasOrd;

Proc CONTENTS Contenido del data set. Proc Contents data=Ventas;

Lista alfabtica de variables y atributos Nm 5 1 6 4 2 3 7 Variable Cantidad Mes Precio Tipo Trim Vendedor Venta Tipo Numrica Alfanumrica Numrica Alfanumrica Alfanumrica Alfanumrica Numrica Longitud 8 8 8 16 8 14 8

EJERCICIOS
EJERCICIO1: Monto de multas de trfico por estado (USA). Imprimir el archivo de datos ordenado por monto y por estado. estado EJERCICIO2: Imprimir el archivo de datos ordenados por ventas, departamento, vendedor. Calcular t t l totales d venta de t por Departamento, D t t por Vendedor V d d EJERCICIO3: Lectura de Datos con diferentes formatos EJERCICIO4: Ventas por departamento y vendedor. vendedor Calcular comisiones por ventas. Tablas Frecuencia de ventas. Total comisiones por vendedor y por departamento EJERCICIO5: Creacin de Libreras permanentes. Datos climticos. y Archivos

1_Ejercicio1.Monto

de multas de trfico por estado (USA). Imprimir el archivo de datos ordenados por monto y por estado

ods html file='c:\DataSas\Ejer1.html'; Data Ejer1; Input Estado $ Monto @@; Datalines; AL 100 HI 200 DE 20 IL 1000 AK 300 CT 50 AR 100 IA 60 FL 250 KS 90 AZ 250 IN 500 CA 100 LA 175 GA 150 MT 70 ID 100 KY 55 CO 100 ME 50 NE 200 MA 85 MD 500 NV 1000 MO 500 MI 40 NM 100 NJ 200 MN 300 NY 300 NC 1000 MS 100 ND 55 OH 100 NH 1000 OR 600 OK 75 SC 75 RI 210 PA 46.50 TN 50 SD 200 TX 200 VT 1000 UT 750 WV 100 VA 200 WY 200 WA 77 Wi 300 DC. DC ; run; ods html close;

1_Ejercicio2.

Ventas por departamento y vendedor: Imprimir el archivo de datos ordenados por ventas, departamento, vendedor. Calcular totales de venta por Departamento, por Vendedor ods html file='c:\DataSas\Ejer2.html'; \ \ j ; Data Ejer2; Input Vendedor Departamento Ventas; Datalines;
V1Ropa V2Zapatos V3Ropa V4Zapatos V3Ropa V3Zapatos V1Ropa V2Zapatos V2Ropa V1Zapatos V1Ropa V2Zapatos V3Zapatos V4Zapatos V3Zapatos V4Ropa 10.5 10 5 12.6 20.1 18.6 17 3 17.3 16.0 15.2 11.8 13 3 13.3 19.1 21.5 30.2 28 5 28.5 26.2 27.6 30.0

1_Ejercicio 3. Lectura de Datos con diferentes formatos


A A A C O P A L A V S B A 1 6 4 . 9 9 . 8 6 1 1 2 1 2 9 5 9 8 2 0 1 1 9 6 1 9 8 2 8 3 4 6 8 2 3 1 1 5 2 0 1 0 1 7

Variables: Cdigo, Horas, Combustible, Ingreso, Vuelos

1_Ejercicio 4. Ventas por departamento y vendedor 1-Calcular comisiones por ventas. Comisin: 5% de las ventas de ropa 7% de las ventas de zapatos

2-Tablas de Frecuencia de ventas 3-Total comisiones por vendedor y por p departamento

DATOS FECHAS (DATE- TIME)


Ejemplo 1. Mostrar M t un mismo i valor l como:
Fecha: DATE Hora: TIMEAMPM Fecha y Hora: DATETIME Funcin MONTH: extrae el mes del valor de Date1. Date1

Ejemplo 2. Leer y escribir fechas


Lee fechas usando el informat MMDDYY8. Escribe fechas calculadas usando el formato DATE9.

Ejemplo 3. Leer fechas y calcular duracin


Leer fechas usando Date9. Calcular duracin proyectos.

Ejemplo 1
ods html file='C:\DataSas\html\1_Fecha1.html'; Data fecha; Hora1=86399; format Hora1 datetime.; Fecha1=86399; format Fecha1 date.; date ; Hora2=86399; format Hora2 timeampm.; Fecha1Mes=month(Fecha1); run; Proc Print data=fecha noobs; title 'Mismo Nmero, , Diferentes Valores SAS'; ; footnote1 'Hora1 es SAS DATETIME'; footnote2 'Fecha1 es SAS DATE '; footnote3 'Hora2 es SAS TIME '; footnote4 'Fecha1Mes es el mes de Fecha1'; run; title; f titl footnote; t t ods html close;

Ejemplo 1

ods html file='C:\DataSas\html\1_Fecha1.html'; \DataSAS\html\1_Ejer1.html

Hora1 01JAN60:23:59:59

Fecha1 20JUL96

Hora2 11:59:59 PM

Fecha1Mes 7

Ejemplo 2
ods d ht html l fil file='C:\DataSas\html\1_Fecha2.html'; 'C \D t S \ht l\1 F h 2 ht l' Data Reunion; Input p Region g $ Reunion : mmddyy10.; yy ; mail_envio = Reunion-45; datalines; N 11-24-11 11 24 11 S 12-28-11 E 12-03-11 W 10-04-11 ; run; proc print data=reunion noobs; format reunion mail_envio date9.; title 'Cronograma Envio @mail'; run; title; ods html close;

Ejemplo 2
ods html file= file='C:\DataSas\html\1 C:\DataSas\html\1_Fecha2.html Fecha2 html'; ; \DataSAS\html\1 Fecha2 html \DataSAS\html\1_Fecha2.html

Regin N S E W

Reunin 24NOV2011 28DEC2011 03DEC2011 04OCT2011

mail_envo 10OCT2011 13NOV2011 19OCT2011 20AUG2011

Ejemplo 3
1-file='C:\DataSas\sas\1_Fecha3.sas'; \DataSAS\sas\Dia1bcv_IntroduccionSAS\1_Fecha3.sas 2-ods html file='C:\DataSas\html\1_Fecha3.html'; \DataSAS\html\1_Fecha3.html

Obs 1 2 3 4

Proid p398 p942 p167 p250

IniFecha

FinFecha

Duracion 16 47 62 7

17OCT1997 02NOV1997 22JAN1998 10MAR1998 15DEC1999 15FEB2000 04JAN2001 11JAN2001

Recursos SAS online:


1. Documentation in SAS help: In SAS, click Help SAS Help and Documentation. 2. Expand SAS Products Base SAS SAS Language Concepts SAS System Concepts. 3 Expand 3. E d SAS L Language El Elements and d view i topics i of f i interest. 4. Expand Dates, Times, and Intervals and view topics. 5. Expand Learning to Use SAS Sample SAS Programs. 6. Click Base SAS Working with Dates in the SAS System,Ch13

Pginas de soporte y consulta SAS:


http://support.sas.com/documentation/92/index.html SAS Technical Support Documents Documentation http://support.sas.com/documentation/cdl/en/leforinforref/63324/HTML/default/n09 mk4h1ba9wp1n1tc3e7x0eow8q.htm SAS Online Product Documentation http://support.sas.com/documentation/cdl/en/basess/58133/HTM L/default/viewer.htm#a001334449.htm

1_Ejercicio 5. Librera SAS. Archivos Permanentes


Format format Date worddate18. format Date date9.; ; Millions dollar6.;

http://support.sas.com/documentation/cdl/en/leforinforref/63324/HTML /default/viewer htm#n11m54nggvjybhn1w2a8mbczw04q htm /default/viewer.htm#n11m54nggvjybhn1w2a8mbczw04q.htm

Ejercicios: Correr los Data Steps que se presentan a continuacin. Analizar los formatos. Verificar posibles errores. Corregir errores.

1-Crear el Data Set USCLIM.HURRICANE data usclim.hurricane; Input Estado Fecha Muertes Perdida Nombre; format Fecha worddate18. Costo dollar6.; informat Estado $char11. $char11 Fecha date9 date9.; ; label Perdida=Costo'; datalines; Mississippi 14aug69 256 1420 Camille Florida o da 14jun72 ju 117 2100 00 Agnes g es Alabama 29aug79 5 2300 Frederick Texas 15aug83 21 2000 Alicia Texas 03aug80 28 300 Allen ;

1-DATA Step para crear el Data Set USCLIM.HURRICANE libname usclim 'C:\DataSAS'; data usclim.huracan; input @1 Estado $char11. @13 Fecha date7. Muertes Perdida Nombre $; format Fecha worddate18. Perdida dollar6.; informat Estado $char11. $char11 Fecha date9 date9.; label Millions='Dao'; datalines; pp 14aug69 g 256 1420 Camille Mississippi Florida 14jun72 117 2100 Agnes Alabama 29aug79 5 2300 Frederick Texas 15aug83 21 2000 Alicia Texas 03aug80 28 300 Allen ; Obs Estado Fecha Muertes Perdida Nombre Proc print; run;
1 Mississippi pp August g 14, 1969 2 3 4 5 Florida June 14, 1972 256 117 5 21 28 $1,420 $2,100 $2,300 $2,000 $300 Camille Agnes Frederic Alicia Allen

Alabama August 29, 1979 Texas August 15, 1983 Texas August 3, 1980

2- Crear el Data Set USCLIM.LOWTEMP data usclim.lowtemp; Input Estado $char14. $char14 Ciudad $char14. $char14 Temp_F Temp F Fecha $ Elevacion; datalines;
Alaska Prospect Creek -80 23jan71 1100 Colorado Maybell -60 01jan79 5920 Idaho Island Prk Dam -60 18jan43 6285 Minnesota Pokegama Dam -59 16feb03 1280 North Dakota Parshall -60 15feb36 1929 South Dakota McIntosh -58 17feb36 2277 Wyoming Moran -63 09feb33 6770 ;

3- Crear el Data Set USCLIM.TEMPCHNG data usclim.tempchng; input @1 Estado $char13. @15 Fecha date7. Tem_In Tem_Fn Minutos; Diff= Tem_Fn Tem_In ; informat estado $char13. Fecha date7.; format Fecha date9.; datalines;
North South South South South Dakota Dakota Dakota Dakota Dakota 21feb18 22jan43 12jan11 22jan43 10jan11 -33 50 720 -4 4 45 2 49 -13 120 54 -4 27 55 8 15 ;

libname clima 'C:\DataSAS'; 4-Crear el Data Set CLIMA.HIGHTEMP data clima.hightemp; clima hightemp; input Sitio $ 1-13 Fecha $ tem_F tem_C; datalines; Libya 13sep22 136 58 California 10jul13 134 57 Israel 21jun42 129 54 Argentina 11dec05 120 49 Saskatchewan 05jul37 113 45 ; 5-Crear el Data Set CLIMA.LOWTEMP data clima.lowtemp; input Sitio $ 1-13 Fecha $ datalines; ; Antarctica 21jul83 -129 -89 Siberia 06feb33 -90 -68 Greenland 09jan54 -87 87 -66 66 Yukon 03feb47 -81 -63 Alaska 23jan71 -80 -67 ; tem_F tem_C;

6-Crear el Data Set PRECPITA.RAIN data precpita.rain; input Sitio $ 1-12 1 12 @13 Fecha date7. date7 Inch Cms; format Fecha date9.; datalines; L R La Reunion i 15 15mar52 52 74 188 Taiwan 10sep63 49 125 Australia 04jan79 44 114 Texas 25jul79 43 109 Canada 06oct64 19 49 ; 7-Crear el Data Set PRECPITA.SNOW data precpita.snow; input Sitio $ 1 1-12 12 @13 Fecha date7. Inch Cms; format Fecha date9.; datalines; Colorado 14apr21 76 193 Alaska 29dec55 62 158 France 05apr69 68 173;

8-DATA Step to Create the Data Set STORM.TORNADO lib libname storm t 'SAS-data-library'; 'SAS d t lib ' data storm.tornado; input Estado $ 1-12 @13 Fecha date7. Muertes Perdida; format Date date9. Perdida dollar6.; label Perdida=Costo en Millones'; datalines; Iowa 11apr65 257 200 Texas 11may70 26 135 Nebraska 06may75 3 400 Connecticut 03oct79 3 200 Georgia 31mar73 9 115 ;

SAS/ASSIST

SAS/ASSIST: DATA MANAGEMENT

S-ar putea să vă placă și