Published on :
ETL MIXTE

Bulk Load Programs Example

This code is also available in: Deutsch Español Français
Awaiting validation
The script begins by assigning a SAS© libname (`mybulk`) to an external data source (potentially SQL Server via ODBC), with the bulk loading option enabled (`bcp=yes`). It then deletes an existing table (`DUBLKTAB`) in this data source to ensure a clean state. A temporary SAS© dataset (`work.DUBLKDAT`) is created in memory from literal data (`datalines`). This dataset is then used to populate the `DUBLKTAB` table in the external database, thus performing the bulk loading operation. Finally, the script uses `PROC PRINT` to display the contents of the `DUBLKTAB` table from the external database, formatting a date column for better readability.
Data Analysis

Type : MIXTE


The initial data is created internally via a DATA STEP with `datalines` (`work.DUBLKDAT`). It is then transferred to an external database table (`mybulk.DUBLKTAB`) via ODBC.

1 Code Block
LIBNAME Statement
Explanation :
Assigns a SAS libname named `mybulk` to an external data source. The macro variables `&dbms` and `&connopt` should contain the specific database connection information (likely ODBC). The `bcp=yes` option enables the bulk copy protocol, typically used with SQL Server, for optimized data transfers.
Copied!
1LIBNAME mybulk &dbms &connopt bcp=yes;
2 Code Block
PROC DELETE
Explanation :
Deletes the `DUBLKTAB` table from the external data source (identified by the `mybulk` libname). This ensures that any previous execution does not leave residues, allowing for a clean recreation of the table.
Copied!
1PROC DELETE DATA=mybulk.DUBLKTAB;
2RUN;
3 Code Block
DATA STEP Data
Explanation :
Creates a temporary SAS dataset named `work.DUBLKDAT`. The data is defined inline using the `cards;` statement. This dataset contains four variables: `name` (character), `age` (numeric), `sex` (character), and `bdate` (date in MMDDYY format).
Copied!
1DATA work.DUBLKDAT;
2 INPUT name $ age sex $ bdate mmddyy.;
3 CARDS;
4amy 3 f 030185
5bill 12 m 121277
6charlie 35 m 010253
7david 19 m 101469
8elinor 42 f 080845
9pearl 78 f 051222
10vera 96 f 101200
11frank 24 m 092663
12georgia 1 f 040687
13henry 46 m 053042
14joann 27 f 020461
15buddy 66 m 101432
16;
17RUN;
4 Code Block
DATA STEP Data
Explanation :
This DATA STEP reads the `work.DUBLKDAT` dataset and writes its records to a new database table named `DUBLKTAB` under the `mybulk` libname. This is the step where the bulk loading of data to the external database occurs.
Copied!
1DATA mybulk.DUBLKTAB;
2 SET work.DUBLKDAT;
3RUN;
5 Code Block
PROC PRINT
Explanation :
Displays the contents of the `DUBLKTAB` table from the external database. The `format bdate date7.;` statement is used to display the `bdate` variable in a readable date format (DDMMMYY). The title 'proc print of table' is added to the output.
Copied!
1PROC PRINT DATA=mybulk.DUBLKTAB;
2 FORMAT bdate date7.;
3title 'proc print of table';
4RUN;
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