Die Beispiele verwenden generierte Daten (Datalines) oder SASHELP.
1 Codeblock
DATA STEP Data
Erklärung : Dieses Beispiel zeigt die Verkettung zweier Tabellen (animal1 und plant1) mithilfe der SET-Anweisung ohne die BY-Anweisung. Die Zeilen von 'plant1' werden einfach an das Ende von 'animal1' angehängt. Dies ist eine grundlegende Operation zum Kombinieren von Daten.
Kopiert!
data animal1;
input Common $ Animal $ 3-8 Number 10-11;
datalines;
a Ant 1
b Bird 2
c Cat 3
d Dog 4
e Eagle 5
f Frog 6
g Goose 7
h Hawk 8
i Impala 9
;
data plant1;
input Common $ Plant $ 3-10 Number 12-13;
datalines;
a Grape 1
c Hazelnut 2
e Indigo 3
g Jicama 4
i Kale 5
;
/* Concaténer animal1 et plant1 */
data append_basique;
set animal1 plant1;
run;
proc print data=append_basique;
title '1. Concaténation de tables Animal et Plant (Base SAS)';
run;
1
DATA animal1;
2
INPUT Common $ Animal $ 3-8 Number 10-11;
3
DATALINES;
4
a Ant 1
5
b Bird 2
6
c Cat 3
7
d Dog 4
8
e Eagle 5
9
f Frog 6
10
g Goose 7
11
h Hawk 8
12
i Impala 9
13
;
14
15
DATA plant1;
16
INPUT Common $ Plant $ 3-10 Number 12-13;
17
DATALINES;
18
a Grape 1
19
c Hazelnut 2
20
e Indigo 3
21
g Jicama 4
22
i Kale 5
23
;
24
25
/* Concaténer animal1 et plant1 */
26
DATA append_basique;
27
SET animal1 plant1;
28
RUN;
29
30
PROC PRINTDATA=append_basique;
31
title '1. Concaténation de tables Animal et Plant (Base SAS)';
32
RUN;
2 Codeblock
DATA STEP Data
Erklärung : Dieses Beispiel verwendet die BY-Anweisung mit einer einzelnen Variablen ('Common'), um die Datensätze der Tabellen 'animal1' und 'plant1' zu verschachteln. Die Zeilen werden basierend auf den entsprechenden Werten der Variablen 'Common' kombiniert.
Kopiert!
data animal1;
input Common $ Animal $ 3-8 Number 10-11;
datalines;
a Ant 1
b Bird 2
c Cat 3
d Dog 4
e Eagle 5
f Frog 6
g Goose 7
h Hawk 8
i Impala 9
;
data plant1;
input Common $ Plant $ 3-10 Number 12-13;
datalines;
a Grape 1
c Hazelnut 2
e Indigo 3
g Jicama 4
i Kale 5
;
/* Entrelacer animal1 et plant1 par la variable COMMON */
data interleave_by_common;
set animal1 plant1;
by common;
run;
proc print data=interleave_by_common;
title '2. Entrelacement par la variable COMMON (Base SAS)';
run;
1
DATA animal1;
2
INPUT Common $ Animal $ 3-8 Number 10-11;
3
DATALINES;
4
a Ant 1
5
b Bird 2
6
c Cat 3
7
d Dog 4
8
e Eagle 5
9
f Frog 6
10
g Goose 7
11
h Hawk 8
12
i Impala 9
13
;
14
15
DATA plant1;
16
INPUT Common $ Plant $ 3-10 Number 12-13;
17
DATALINES;
18
a Grape 1
19
c Hazelnut 2
20
e Indigo 3
21
g Jicama 4
22
i Kale 5
23
;
24
25
/* Entrelacer animal1 et plant1 par la variable COMMON */
26
DATA interleave_by_common;
27
SET animal1 plant1;
28
BY common;
29
RUN;
30
31
PROC PRINTDATA=interleave_by_common;
32
title '2. Entrelacement par la variable COMMON (Base SAS)';
33
RUN;
3 Codeblock
DATA STEP Data
Erklärung : Dieses Beispiel demonstriert eine fortgeschrittenere Verschachtelung mithilfe der BY-Anweisung mit zwei Variablen ('Common' und 'Number'). Dies ermöglicht eine granularere Steuerung der Reihenfolge, in der die Zeilen der beiden Tabellen 'animal1' und 'plant1' kombiniert werden.
Kopiert!
data animal1;
input Common $ Animal $ 3-8 Number 10-11;
datalines;
a Ant 1
b Bird 2
c Cat 3
d Dog 4
e Eagle 5
f Frog 6
g Goose 7
h Hawk 8
i Impala 9
;
data plant1;
input Common $ Plant $ 3-10 Number 12-13;
datalines;
a Grape 1
c Hazelnut 2
e Indigo 3
g Jicama 4
i Kale 5
;
/* Entrelacer animal1 et plant1 par COMMON et Number */
data interleave_by_common_number;
set animal1 plant1;
by common Number;
run;
proc print data=interleave_by_common_number;
title '3. Entrelacement par COMMON et Number (Base SAS)';
run;
1
DATA animal1;
2
INPUT Common $ Animal $ 3-8 Number 10-11;
3
DATALINES;
4
a Ant 1
5
b Bird 2
6
c Cat 3
7
d Dog 4
8
e Eagle 5
9
f Frog 6
10
g Goose 7
11
h Hawk 8
12
i Impala 9
13
;
14
15
DATA plant1;
16
INPUT Common $ Plant $ 3-10 Number 12-13;
17
DATALINES;
18
a Grape 1
19
c Hazelnut 2
20
e Indigo 3
21
g Jicama 4
22
i Kale 5
23
;
24
25
/* Entrelacer animal1 et plant1 par COMMON et Number */
26
DATA interleave_by_common_number;
27
SET animal1 plant1;
28
BY common Number;
29
RUN;
30
31
PROC PRINTDATA=interleave_by_common_number;
32
title '3. Entrelacement par COMMON et Number (Base SAS)';
33
RUN;
4 Codeblock
DATA STEP / PROC CASUTIL Data
Erklärung : Dieses Beispiel demonstriert, wie eine Verschachtelung von Tabellen in der CAS-Umgebung durchgeführt wird. Es beginnt mit der Erstellung von Basis-SAS-Tabellen, lädt diese mithilfe von PROC CASUTIL als CAS-Tabellen und verwendet dann einen DATA Step mit der BY-Anweisung, um die Tabellen direkt im verteilten Speicher zu verschachteln. Die Verarbeitungsreihenfolge in CAS kann aufgrund von Parallelität und Partitionierung von der von Base SAS abweichen. Die Variable `_hostname_` wird hinzugefügt, um zu beobachten, auf welchem Knoten die Daten verarbeitet wurden, was die verteilte Natur von CAS veranschaulicht.
Kopiert!
libname mycas cas;
data animal_cas;
input Common $ Animal $ 3-8 Number 10-11;
datalines;
a Ant 1
b Bird 2
c Cat 3
d Dog 4
e Eagle 5
f Frog 6
g Goose 7
h Hawk 8
i Impala 9
;
data plant_cas;
input Common $ Plant $ 3-10 Number 12-13;
datalines;
a Grape 1
c Hazelnut 2
e Indigo 3
g Jicama 4
i Kale 5
;
proc casutil;
load data=animal_cas outcaslib='CASUSER' casout='ANIMAL_CAS' replace;
load data=plant_cas outcaslib='CASUSER' casout='PLANT_CAS' replace;
run;
/* Entrelacer les tables CAS par la variable COMMON */
data mycas.interleaveByCommonCas;
set mycas.animal_cas mycas.plant_cas;
by common;
/* La variable _hostname_ peut être utile pour observer la distribution */
hostname=_hostname_;
run;
proc print data=mycas.interleaveByCommonCas;
title '4. Entrelacement par COMMON dans un DATA Step en CAS';
run;
/* Nettoyage des tables CAS */
proc casutil;
droptable casdata='ANIMAL_CAS' incaslib='CASUSER';
droptable casdata='PLANT_CAS' incaslib='CASUSER';
droptable casdata='INTERLEAVEBYCOMMONCAS' incaslib='CASUSER';
run;
Dieses Material wird von We Are Cas "wie besehen" zur Verfügung gestellt. Es gibt keine ausdrücklichen oder stillschweigenden Garantien hinsichtlich der Marktgängigkeit oder Eignung für einen bestimmten Zweck in Bezug auf die hierin enthaltenen Materialien oder Codes. We Are Cas ist nicht verantwortlich für Fehler in diesem Material, wie es jetzt existiert oder existieren wird, noch bietet We Are Cas technischen Support dafür an.
Zugehörige Dokumentation
Aucune documentation spécifique pour cette catégorie.
SAS und alle anderen Produkt- oder Dienstleistungsnamen von SAS Institute Inc. sind eingetragene Marken oder Marken von SAS Institute Inc. in den USA und anderen Ländern. ® zeigt die Registrierung in den USA an. WeAreCAS ist eine unabhängige Community-Site und nicht mit SAS Institute Inc. verbunden.
Diese Website verwendet technische und analytische Cookies, um Ihre Erfahrung zu verbessern.
Mehr erfahren.