The difference between implicit and explicit writing (OUTPUT) is often a source of confusion for beginners, yet it's what gives the Data Step all its power.
On forums, the question often comes up: "I understand the theory, but when should I use one or the other?"
By default, every Data step has an implicit (automatic) output statement at the very end of the code, just before the RUN. The cycle proceeds as follows:
It writes the row to the output table (Implicit Output).
It clears the PDV (Program Data Vector) and returns to the beginning to read the next observation.
This is why you don't need to write OUTPUT for a simple copy:
data test;
set source;
/* L'output se fait tout seul ici ! */
run;
1
DATA test;
2
SETSOURCE;
3
/* L'output se fait tout seul ici ! */
4
RUN;
Note : Taking Control: Explicit Output
As soon as you write the OUTPUT keyword (or OUTPUT table_name) somewhere in your Data step, you disable the automatic implicit output.
data hommes femmes;
set demog;
if sexe = 'M' then output hommes; /* Écrit seulement dans la table HOMMES */
else if sexe = 'F' then output femmes; /* Écrit seulement dans la table FEMMES */
run;
1
DATA hommes femmes;
2
SET demog;
3
IF sexe = 'M'THENOUTPUT hommes; /* Écrit seulement dans la table HOMMES */
4
ELSEIF sexe = 'F'THENOUTPUT femmes; /* Écrit seulement dans la table FEMMES */
5
RUN;
Note : Case B: Aggregation and Filtering (Controlling write frequency)
The second expert shows how to reduce the number of rows (aggregation) without using a statistical procedure (PROC MEANS).
The idea is to perform calculations row by row (sums, counters), but only write the result at the end of a group (when last.variable is true).
data synthese;
set ventes;
by produit; /* Nécessaire pour utiliser first. et last. */
/* Accumulation des sommes... */
if first.produit then total = 0;
total + montant;
/* On écrit SEULEMENT quand le groupe est fini */
if last.produit then output;
run;
1
DATA synthese;
2
SET ventes;
3
BY produit; /* Nécessaire pour utiliser first. et last. */
4
5
/* Accumulation des sommes... */
6
IF first.produit THEN total = 0;
7
total + montant;
8
9
/* On écrit SEULEMENT quand le groupe est fini */
10
IF last.produit THENOUTPUT;
11
RUN;
In this example:
If you had left the implicit output, you would have had one output row for each input row (with partial totals).
With the conditional explicit output (if ... then output), you only get one row per product.
Summary: The Golden Rule
Type
Description
When to use it?
Implicit
Automatic at the end of the step.
For simple transformations (1 input row = 1 output row).
Explicit
Manual via the OUTPUT statement. Disables the automatic behavior.
To split data (1 to N tables), multiply rows (1 to N rows), or aggregate (N to 1 row).
Technical Note: Another frequent use mentioned is parsing complex files. If a text file contains mixed headers, details, and footers, explicit output allows sending the headers to table A and the details to table B, all in a single pass.
Wichtiger Haftungsausschluss
Die auf WeAreCAS.eu bereitgestellten Codes und Beispiele dienen Lehrzwecken. Es ist zwingend erforderlich, sie nicht blind in Ihre Produktionsumgebungen zu kopieren. Der beste Ansatz besteht darin, die Logik zu verstehen, bevor sie angewendet wird. Wir empfehlen dringend, diese Skripte in einer Testumgebung (Sandbox/Dev) zu testen. WeAreCAS übernimmt keine Verantwortung für mögliche Auswirkungen oder Datenverluste auf Ihren Systemen.
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.