Published on :
ETL INTERNAL_CREATION

Example of DATA STEP usage with PROC APPEND

This code is also available in: Deutsch Español Français
Awaiting validation
The script begins by attempting to delete a table named 'new1' in the 'mydblib' library. Then, a first DATA STEP tries to create 'mydblib.new1' from 'work.new', which will fail because 'work.new' does not yet exist. The script corrects this by creating 'work.new' with a simple variable 'x'. After this creation, a second DATA STEP successfully creates 'mydblib.new1' from 'work.new'. Finally, the 'mydblib.new1' table is deleted again. The main objective is to demonstrate conditional table creation logic and error handling related to data sources.
Data Analysis

Type : INTERNAL_CREATION


The data used ('work.new') is created directly within the script via a DATA STEP. The 'mydblib' library is a reference to an external library (Impala in the original comment's context), but the 'new1' data is generated and manipulated within this environment, without dependence on unmanaged external files.

1 Code Block
PROC DELETE
Explanation :
This block attempts to delete the 'new1' table in the 'mydblib' library. This is an initial cleanup operation or handling cases where the table might already exist.
Copied!
1PROC DELETE DATA=mydblib.new1;
2RUN;
2 Code Block
DATA STEP
Explanation :
This DATA STEP attempts to create the 'mydblib.new1' table by reading data from the temporary dataset 'work.new'. At this stage of the script, 'work.new' does not exist, so this block is intended to fail and illustrates an error scenario.
Copied!
1DATA mydblib.new1;
2 SET work.new;
3RUN;
3 Code Block
DATA STEP Data
Explanation :
This DATA STEP creates the temporary dataset 'work.new' with a single observation and a variable 'x' with the value 1. This step is crucial for the subsequent DATA STEP to execute correctly.
Copied!
1DATA work.new;
2x=1;
3RUN;
4 Code Block
DATA STEP Data
Explanation :
After 'work.new' is created, this DATA STEP successfully creates 'mydblib.new1' by copying data from 'work.new'. This demonstrates the success of the operation after resolving the data source dependency.
Copied!
1DATA mydblib.new1;
2 SET work.new;
3RUN;
5 Code Block
PROC DELETE
Explanation :
This block deletes the 'new1' table from 'mydblib' again, completing the test cycle by cleaning up the created table.
Copied!
1PROC DELETE DATA=mydblib.new1;
2RUN;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
Copyright Info : S A S S A M P L E L I B R A R Y