Documentos de Académico
Documentos de Profesional
Documentos de Cultura
2 2-SasBcv CombinacionArchivos
2 2-SasBcv CombinacionArchivos
BASICO
Giampaolo Orlandoni Josefa Ramoni
2_CombinarSET_1.sas
Input Nombre $ Edad Sexo $ Sueldo; Input Nombre $ Edad Sexo $ Sueldo;
Concatenacin de archivos
A1
NOMBRE
JUAN LUISA RAUL SAUL JULIA
A2
CODIGO
NA1 NA1 NA1 NA1 NA1
SEXO
M F M M F
NOMBRE
NORA RAUL
SEXO
F M
CODIGO
NA2 NA2
Concatenacin de archivos
A1 NOMBRE SEXO CODIGO Data c; SET A1 A2; run; A2 NOMBRE SEXO CODIGO
3-Data Dep1_2
Obs 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Nombre Vincente Felipe Tomas Nicolas Gisela Humberto Emily Michaela Martin Maria Odilia Tomas Luis Benito Francisc Edad 34 28 27 36 32 39 22 32 40 45 28 33 38 29 41 Sexo M M M M F M F F M F F M M M M Sueldo 1000 2000 1800 3000 3500 1900 2600 2500 3500 4500 2975 2750 3390 2800 3500
2-Data Dep2
Obs 1 2 3 4 5 6 7 Nombre Martin Maria Odilia Tomas Luis Benito Francisc Edad 40 45 28 33 38 29 41 Sexo M F F M M M M Sueldo 3500 4500 2975 2750 3390 2800 3500
2_CombinarSET_2,sas:
Input Nombre $ Edad Sexo $ Sueldo; Input Nombre $ Edad Sexo $;
El DS contiene todas las variables: Nombre$ Edad Sexo$ Sueldo Se generan datos faltantes para las observaciones que no tienen informacin de alguna variable.
Las variables deben tener los mismos atributos (mismo tipo). De lo contrario la concatenacin no se realiza y el programa produce un error. Ejemplo: j p Edad numrica en Dep1 p Edad alfanumrica en Dep2
ERROR:LavariableEdadsehadefinidocomoalfanumricaycomonumrica.
3-Data Dep1_2
Obs 1 2 3 4 5 6 7 8
Nombre
Vincente Felipe Tomas Nicolas Gisela Humberto Emily Michaela Martin Maria Odilia Tomas Luis Benito Francisco
Edad
34 28 27 36 32 39 22 32 40 45 28 33 38 29 41
Sexo
M M M M F M F F M F F M M M M
Sueldo
1000 2000 1800 3000 3500 1900 2600 2500 . . . . . . .
2-Data Dep2
Obs 1 2 3 4 5 6 7 Nombre Martin Maria Odilia Tomas Luis Benito Francisc Edad 40 45 28 33 38 29 41 Sexo M F F M M M M
9 10 11 12 13 14 15
Nombre: nombre estudiante. An: ao estudio: 1 1, 2 2, 3 3, 4 4 Especialidad: area de especializacin (valor faltante para 1 y 2 aos).
Programa: El siguiente programa ejecuta un Merge One-toOne de los DS, asignando un horario a cada estudiante de la clase en el orden de los datos
data Clase; Input Name $ 1-25 Year $ 26-34 Spec $ 36-50; data Horario; Input Date date9. @12 Time $ @19 Room $;
Merge One-to-One
Clase
Obs 1 2 3 4 5 6 Nombre Azuaje, Juan Carter, Tomas Perez, Elisa Tamayo, Raquel Uzon, Rolando Wiky, Mauricio An prim terc cuar prim segn terc Arte 3 4 Arte Matematica 1 2 Azuaje, Juan Carter, Tomas Perez, Elisa Tamayo, Raquel Uzon, Rolando Wiky, Mauricio prim terc cuar prim Arte 14SEP2010 10:00 103 14SEP2010 10:30 103 Espec
Horario
Obs 1 2 3 4 5 6 Fecha 14SEP2010 14SEP2010 14SEP2010 15SEP2010 15SEP2010 17SEP2010 Hora 10 00 10:00 10:30 11:00 10:00 10:30 11:00 Sala 103 103 207 105 105 207
segn
terc
Arte
Ejemplo: 1-Data Dep1; Sueldo; 2-Data Dep2; Input Nombre $ 1-10 Edad Sexo $
proc sort data=Dep1 out=WORK.Tabla1; proc sort data=Dep2 out=WORK.Tabla2; 3-Data Dep1_2_Merge1;
by SEXO; by SEXO;
1-Data Company; Input Nom $ 1-25 Edad 27-28 Sexo $ 30; proc sort data=company; by Nom; 2-Data Finanza; Input IdNum $ 1-11 Nom $ 13-40 Sueldo; proc sort data=finanza; by Nom; 3-Data CompaFina; Merge company finanza; by nom;
Combinacin de archivos
VUELO
VUELO
921 982 114 431
PRECIOS
DESTINO
DFW DFW LAX LAX
PASAJERO
169 120 185 103
DESTINO
DFW FRA LAX LON
CIUDAD
PRECIO
600 1200 900 900
data Ingreso(keep= vuelo ciudad ingreso); MERGE vuelo precios; p ; By destino; ingreso=pasajeros*precio; Run;
VUELO
PASAJERO DESTINO
CIUDAD
PRECIO
BY variable identificadora; Update slo puede manejar dos DS El comando d BY indica i di l las variables i bl match t h Ambos DS deben estar ordenados por variables match especificadas en BY. las mismas
Statement/ Procedure
Action Performed
BY
Controls the operation of a SET, MERGE, UPDATE, or MODIFY statement in the DATA step and sets up special grouping variables. BY-group processing is a means of processing observations that have the same values of one or more variables. Reads observations from two or more SAS DS and joins them into a single observation. When using MERGE with BY, the data must be sorted or indexed on the BY variable. Processes observations in a SAS data set Sorted or indexed data are not required for use with BY, but are recommended for performance in place place. (Contrast with UPDATE.) Reads observations from one or more SAS data sets. Applies transactions to observations in a master SAS data set. UPDATE does not update observations in place; it produces an updated copy of the current data set. Both the master and transaction DS must be sorted by y or indexed on the BY variable. Adds observations from one SAS DS to the end of another SAS DS
MERGE
MODIFY
SET
UPDATE
PROC APPEND