Published on :
Data Access CREATION_INTERNE

Informix Data Connector

This code is also available in: Deutsch Español Français
Awaiting validation
The Informix data connector facilitates the integration of data stored in an Informix database with SAS© Viya. It offers options to specify the host, port, database name, user ID, password, as well as Informix-specific options like the database server (SERVER) and locale (DBLOCALE). It allows loading Informix tables into CAS tables and writing CAS tables to Informix, thereby supporting ETL operations and distributed analysis via CAS.
Data Analysis

Type : CREATION_INTERNE


Examples use generated data (datalines) or SASHELP, then load/save this data via the Informix connector.

1 Code Block
PROC CASUTIL / LIBNAME Data
Explanation :
This example demonstrates how to establish a basic connection to an Informix database using the LIBNAME statement. It defines essential connection parameters such as server, host, port, database, user, and password. It then creates a small SAS in-memory table and loads this table into a CAS table. The commented section shows how to load data directly from Informix to CAS. The options must be adapted to your Informix environment.
Copied!
1/* Établit une connexion LIBNAME à la base de données Informix */
2/* Remplacez les valeurs d'hôte, de port, de base de données, d'utilisateur et de mot de passe par les vôtres */
3 
4LIBNAME myinfor INFORMIX
5 SERVER="your_informix_server_name" /* Nom du serveur Informix */
6 HOST="your_informix_host" /* Adresse IP ou nom d'hôte d'Informix */
7 PORT=9088 /* Port par défaut d'Informix */
8 DATABASE="your_informix_db" /* Nom de la base de données Informix */
9 USER="your_username" /* Nom d'utilisateur Informix */
10 PASSWORD="your_password" /* Mot de passe Informix */
11 SCHEMA="your_schema"
12 DBCLIENT_MAX_DATA_BYTES=104857600; /* Option pour la taille maximale des données */
13 
14/* Crée une table SAS en mémoire CAS pour l'exemple */
15DATA casuser.sample_data;
16 INPUT ID Name $ Value;
17 DATALINES;
181 John 100
192 Jane 150
203 Mike 200
21;
22RUN;
23 
24/* Charge la table SAS 'sample_data' dans une table CAS 'informix_table' */
25PROC CASUTIL;
26 LOAD DATA=casuser.sample_data OUTCASLIB=mycaslib CASOUT="informix_table" REPLACE;
27QUIT;
28 
29/* Pour lire depuis Informix vers CAS (si 'my_informix_data' existe dans Informix) */
30/* PROC CASUTIL; */
31/* LOAD DATA=myinfor.my_informix_data OUTCASLIB=mycaslib CASOUT="loaded_informix_data" REPLACE; */
32/* QUIT; */
33 
34LIBNAME myinfor CLEAR;
2 Code Block
PROC CAS / PROC CASUTIL Data
Explanation :
This example shows how to create a CASLIB for Informix, specifying common options like 'DBLOCALE'. It then uses PROC CASUTIL to save a SAS table (sashelp.class) into a new Informix table. Finally, it loads the newly created table from Informix to CAS for verification and prints the first observations. This illustrates a typical workflow for loading SAS data to Informix for later use.
Copied!
1/* Connexion au serveur CAS */
2CAS;
3 
4/* Établit une caslib pour Informix avec des options supplémentaires */
5/* Remplacez les valeurs d'hôte, de port, de base de données, d'utilisateur et de mot de passe par les vôtres */
6 
7CASLIB myinformix_lib datasource=(
8 driver="informix",
9 server="your_informix_server_name",
10 host="your_informix_host",
11 port=9088,
12 database="your_informix_db",
13 username="your_username",
14 password="your_password",
15 schema="your_schema",
16 dblocale="en_US.57372"
17) incaslib; /* incaslib rend la caslib disponible immédiatement */
18 
19/* Crée une table SAS temporaire qui sera chargée dans Informix via CAS */
20DATA _null_;
21 SET sashelp.class;
22 file _webout;
23 OUTPUT;
24RUN;
25 
26DATA casuser.students;
27 SET sashelp.class;
28RUN;
29 
30/* Sauvegarde la table CAS 'students' dans Informix */
31PROC CASUTIL;
32 SAVE DATA=casuser.students
33 CASLIB=myinformix_lib
34 CASOUT="informix_students_table" REPLACE;
35QUIT;
36 
37/* Vérifie que la table a été créée dans Informix et peut être chargée */
38PROC CASUTIL;
39 LOAD DATA=myinformix_lib.informix_students_table
40 CASOUT="loaded_informix_students" REPLACE;
41QUIT;
42 
43PROC PRINT DATA=loaded_informix_students (obs=5);
44RUN;
45 
46CASLIB myinformix_lib_informix DROP;
47CAS TERMINATE;
3 Code Block
PROC CAS / PROC CASUTIL Data
Explanation :
This example illustrates an advanced scenario where filtering (WHERE) and column selection (DROP) options are applied directly when loading data from Informix to CAS. This allows loading only relevant data, thus reducing resource consumption and processing time. The Informix table 'my_large_dataset' is simulated here by a CAS table creation for the autonomy of the example.
Copied!
1/* Connexion au serveur CAS */
2CAS;
3 
4/* Établit une caslib pour Informix (assurez-vous que la connexion est valide) */
5/* Pour cet exemple, nous supposons qu'une table 'my_large_dataset' existe dans Informix */
6/* Remplacez les valeurs d'hôte, de port, de base de données, d'utilisateur et de mot de passe par les vôtres */
7 
8CASLIB myinformix_adv_lib datasource=(
9 driver="informix",
10 server="your_informix_server_name",
11 host="your_informix_host",
12 port=9088,
13 database="your_informix_db",
14 username="your_username",
15 password="your_password",
16 schema="your_schema"
17) incaslib;
18 
19/* Simulation d'une table Informix pour l'exemple */
20/* Normalement, cette table existerait déjà dans votre base de données Informix */
21/* Ici, nous la créons directement dans CAS pour simuler l'accès à une table Informix existante */
22DATA casuser.my_large_dataset;
23 LENGTH id 8 product $20. quantity 8 price 8;
24 DO id = 1 to 1000;
25 product = 'Produit_' || put(ceil(ranuni(0)*10), 2.);
26 quantity = ceil(ranuni(0)*100);
27 price = round(ranuni(0)*1000, 0.01);
28 OUTPUT;
29 END;
30RUN;
31 
32/* Charger sélectivement des données d'Informix avec un filtre et une sélection de colonnes */
33/* Supposons que 'my_large_dataset' est le nom de la table dans Informix */
34PROC CASUTIL;
35 LOAD DATA=myinformix_adv_lib.my_large_dataset(where=(quantity > 50) drop=(price))
36 CASOUT="filtered_informix_data" REPLACE;
37QUIT;
38 
39PROC PRINT DATA=filtered_informix_data (obs=10);
40RUN;
41 
42CASLIB myinformix_adv_lib DROP;
43CAS TERMINATE;
4 Code Block
PROC CAS / PROC CASUTIL Data
Explanation :
This example highlights the use of advanced options for performance (NTHREADS, DBCONNECT_MAX_DATA_BYTES, PRESERVE_CURSORS) and error handling (_ERROR_FILE_, _ERROR_ACTION_) when interacting with Informix via CAS. It simulates a scenario where data with potential errors is recorded, showing how the connector can be configured to handle these situations rather than interrupting the process. The specified error file would allow auditing ignored rows.
Copied!
1/* Connexion au serveur CAS */
2CAS;
3 
4/* Établit une caslib pour Informix avec des options de performance et de gestion d'erreur */
5/* Remplacez les valeurs d'hôte, de port, de base de données, d'utilisateur et de mot de passe par les vôtres */
6 
7CASLIB myinformix_perf_lib datasource=(
8 driver="informix",
9 server="your_informix_server_name",
10 host="your_informix_host",
11 port=9088,
12 database="your_informix_db",
13 username="your_username",
14 password="your_password",
15 schema="your_schema",
16 /* Options de performance */
17 NTHREADS=4, /* Nombre de threads à utiliser pour le transfert de données */
18 DBCONNECT_MAX_DATA_BYTES=104857600, /* Taille maximale des blocs de données */
19 PRESERVE_CURSORS=TRUE, /* Aide à la performance pour des requêtes répétées */
20 /* Options de gestion d'erreur (ex: ignore les lignes erronées, nécessite un fichier de log d'erreurs) */
21 _ERROR_FILE_="/tmp/informix_errors.log",
22 _ERROR_ACTION_="CONTINUE"
23) incaslib;
24 
25/* Crée une table CAS avec des données qui pourraient potentiellement causer des erreurs (simulé) */
26DATA casuser.data_with_potential_errors;
27 INPUT ID Name $ Age;
28 DATALINES;
291 Alice 25
302 Bob 30
313 Charlie . /* Simulation d'une donnée manquante/potentiellement erronée */
324 David 40
33;
34RUN;
35 
36/* Sauvegarde la table CAS dans Informix, avec gestion d'erreurs */
37PROC CASUTIL;
38 SAVE DATA=casuser.data_with_potential_errors
39 CASLIB=myinformix_perf_lib
40 CASOUT="informix_error_test" REPLACE;
41QUIT;
42 
43/* Tente de charger la table pour vérifier */
44PROC CASUTIL;
45 LOAD DATA=myinformix_perf_lib.informix_error_test
46 CASOUT="loaded_error_test" REPLACE;
47QUIT;
48 
49PROC PRINT DATA=loaded_error_test;
50RUN;
51 
52/* Nettoyage */
53CASLIB myinformix_perf_lib DROP;
54CAS TERMINATE;
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.

Related Documentation : Data Access

Sujet / Mot-cléLien vers la ressource
DOC FedSQL en/sampleCode/FEDSQL9D66
Banner
Expert Advice
Expert
Michael
Responsable de l'infrastructure Viya.
« If you encounter connection stability issues, check the PRESERVE_CURSORS=TRUE setting. In Informix, this ensures that cursors remain open across multiple commits, which is a common requirement for complex, multi-step CAS analytical workflows. »