The `upload` action allows data to be transferred from a client-side file or a temporary client-side file to a CAS in-memory table. In this example, `PROC HTTP` is first used to retrieve a CSV file from a remote URL and temporarily save it. Then, the `upload` action is invoked via `PROC CAS` to read this temporary file and send it as a CAS table. Options like `casOut` allow specifying the name of the target table in CAS and managing replacement (`replace=True`). The `importOptions={fileType="csv"}` option ensures that the file is correctly interpreted as a CSV. Once the table is loaded, a `simple.summary` action is executed to provide descriptive statistics grouped by a variable, thus demonstrating data processing in the CAS environment.
Data Analysis
Type : SIMULATED_EXTERNAL_FILE_OR_INTERNAL_CREATION
The examples create internal CSV data or simulate external files to ensure their autonomy.
1 Code Block
PROC CAS / DATA step Data
Explanation : This example shows the direct loading of a small, on-the-fly created CSV file via a `DATA step` in SAS, then transferred to CAS. The `filename` statement with `temp` creates a temporary file, whose path is retrieved by `%sysfunc(pathname(mydata))`. The `table.upload` action is then used to load this file into the CAS session under the name `my_temp_table`. Finally, `table.columnInfo` is used to confirm the loading and structure of the table.
Copied!
/* Configurez votre hôte et port CAS */
*options cashost="cloud.example.com" casport=5570;
*cas casauto;
/* Crée un fichier CSV temporaire à partir de données inline */
filename mydata temp;
data _null_;
file mydata dsd;
put "Name,Age,City";
put "Alice,30,Paris";
put "Bob,24,Lyon";
put "Charlie,35,Marseille";
run;
/* Récupère le chemin d'accès au fichier temporaire */
%let temppath = %sysfunc(quote(%sysfunc(pathname(mydata))));
/* Charge le fichier CSV temporaire dans CAS */
proc cas;
upload path=&temppath.
casOut={
name='my_temp_table',
replace=True
},
importOptions={fileType="csv"};
run;
/* Vérifie que la table est chargée en affichant ses colonnes */
proc cas;
table.columnInfo / table='my_temp_table';
run;
quit;
/* Vérifie que la table est chargée en affichant ses colonnes */
29
PROC CAS;
30
TABLE.columnInfo / TABLE='my_temp_table';
31
RUN;
32
QUIT;
2 Code Block
PROC CAS / PROC HTTP Data
Explanation : This example uses `PROC HTTP` to download a CSV file from a remote URL to a temporary file. This file is then loaded into CAS via `table.upload`. The `promote=True` option in `casOut` makes the table globally accessible in the CAS session. To verify the loading, `table.tableInfo` displays the table's metadata, and `simple.summary` calculates basic statistics, illustrating common CAS table management and analysis actions.
Copied!
/* Configurez votre hôte et port CAS */
*options cashost="cloud.example.com" casport=5570;
*cas casauto;
/* URL d'un fichier CSV public */
%let data_url='http://support.sas.com/documentation/onlinedoc/viya/exampledatasets/classfit.csv';
filename temp_csv temp;
/* Simule le téléchargement d'un fichier CSV depuis une URL */
proc http method='get' url=&data_url. out=temp_csv;
run;
/* Récupère le chemin d'accès au fichier temporaire */
%let temppath = %sysfunc(quote(%sysfunc(pathname(temp_csv))));
/* Charge le fichier CSV temporaire dans CAS et le promeut en table globale */
proc cas;
upload path=&temppath.
casOut={
name='class_promote',
replace=True,
promote=True /* Propage la table pour la rendre globale */
},
importOptions={fileType="csv"};
run;
/* Vérifie les informations de la table (action courante) */
proc cas;
table.tableInfo / name='class_promote';
run;
/* Obtient des statistiques sommaires (autre action courante) */
proc cas;
t1.name = 'class_promote';
simple.summary /
table = t1,
subSet = {"N", "MEAN", "STD"};
quit;
/* Charge le fichier CSV temporaire dans CAS et le promeut en table globale */
17
PROC CAS;
18
upload path=&temppath.
19
casOut={
20
name='class_promote',
21
replace=True,
22
promote=True /* Propage la table pour la rendre globale */
23
},
24
importOptions={fileType="csv"};
25
RUN;
26
27
/* Vérifie les informations de la table (action courante) */
28
PROC CAS;
29
TABLE.tableInfo / name='class_promote';
30
RUN;
31
32
/* Obtient des statistiques sommaires (autre action courante) */
33
PROC CAS;
34
t1.name = 'class_promote';
35
SIMPLE.summary /
36
TABLE = t1,
37
subSet = {"N", "MEAN", "STD"};
38
QUIT;
3 Code Block
PROC CAS / DATA step Data
Explanation : This example demonstrates advanced capabilities by loading a CSV file and then using a `DATA step` integrated into `PROC CAS` to manipulate the data. It calculates a new variable, the Body Mass Index (BMI), and filters the dataset to include only male records. Finally, the `simple.summary` action is applied to the resulting table to obtain statistics on the manipulated columns, showing a transformation and analysis in CAS memory.
Copied!
/* Configurez votre hôte et port CAS */
*options cashost="cloud.example.com" casport=5570;
*cas casauto;
/* Crée un fichier CSV temporaire avec des données de santé */
filename health_data temp;
data _null_;
file health_data dsd;
put "ID,Gender,Height_cm,Weight_kg";
put "1,M,175,70";
put "2,F,160,55";
put "3,M,180,85";
put "4,F,165,60";
put "5,M,170,75";
run;
/* Récupère le chemin d'accès au fichier temporaire */
%let temppath = %sysfunc(quote(%sysfunc(pathname(health_data))));
/* Charge le fichier CSV temporaire dans CAS */
proc cas;
upload path=&temppath.
casOut={
name='health_metrics',
replace=True
},
importOptions={fileType="csv"};
run;
/* Manipule les données dans CAS : Calcule l'IMC et filtre par genre */
proc cas;
data casuser.health_bmi / caslib='casuser' replace=True;
set casuser.health_metrics;
BMI = Weight_kg / ((Height_cm / 100) ** 2);
where Gender = 'M'; /* Filtre pour ne conserver que les hommes */
run;
/* Obtient des statistiques sommaires pour la nouvelle table avec l'IMC */
simple.summary /
table='health_bmi',
inputs={'Height_cm', 'Weight_kg', 'BMI'},
subSet = {"MEAN", "MAX", "MIN"};
run;
quit;
/* Manipule les données dans CAS : Calcule l'IMC et filtre par genre */
31
PROC CAS;
32
DATA casuser.health_bmi / caslib='casuser' replace=True;
33
SET casuser.health_metrics;
34
BMI = Weight_kg / ((Height_cm / 100) ** 2);
35
where Gender = 'M'; /* Filtre pour ne conserver que les hommes */
36
RUN;
37
38
/* Obtient des statistiques sommaires pour la nouvelle table avec l'IMC */
39
SIMPLE.summary /
40
TABLE='health_bmi',
41
inputs={'Height_cm', 'Weight_kg', 'BMI'},
42
subSet = {"MEAN", "MAX", "MIN"};
43
RUN;
44
QUIT;
4 Code Block
PROC CAS / DATA step Data
Explanation : This two-part example first illustrates the system's robustness in the face of errors: an attempt to load a non-existent file is made, which will generate an error in the SAS log, highlighting the need for error handling. The second part demonstrates CAS's ability to handle large volumes of data. A large dummy dataset is generated directly in CAS memory via a `DATA step` (`10,000 observations`), and then grouped summary statistics are calculated. This highlights CAS's performance for distributed processing of large data.
Copied!
/* --- Partie 1: Démonstration de la gestion d'erreur avec un fichier inexistant --- */
/* Tente de charger un fichier qui n'existe pas pour montrer une erreur */
/* Cette opération devrait générer une erreur visible dans le log SAS */
filename nonexist temp;
proc cas;
upload path=%sysfunc(quote(%sysfunc(pathname(nonexist))))
casOut={
name='error_test',
replace=True
},
importOptions={fileType="csv"};
run; /* Vérifier le log SAS pour les messages d'erreur de fichier introuvable */
/* --- Partie 2: Simulation de chargement et traitement de gros volumes de données --- */
/* Création d'une table CAS de grande taille (simulée) */
proc cas;
data casuser.large_data (drop=_i_) / caslib='casuser' replace=True;
do _i_ = 1 to 10000; /* 10 000 observations simulées */
ID = _i_;
Category = ceil(rand('UNIFORM') * 5); /* 5 catégories aléatoires */
Value = rand('NORMAL') * 100 + 50;
output;
end;
run;
/* Calcul de statistiques sommaires sur la grande table, groupées par catégorie */
simple.summary /
table='large_data',
inputs={'Value'},
groupBy={'Category'},
subSet = {"N", "MEAN", "STD"};
run;
quit;
1
/* --- Partie 1: Démonstration de la gestion d'erreur avec un fichier inexistant --- */
2
/* Tente de charger un fichier qui n'existe pas pour montrer une erreur */
3
/* Cette opération devrait générer une erreur visible dans le log SAS */
/* Calcul de statistiques sommaires sur la grande table, groupées par catégorie */
27
SIMPLE.summary /
28
TABLE='large_data',
29
inputs={'Value'},
30
groupBy={'Category'},
31
subSet = {"N", "MEAN", "STD"};
32
RUN;
33
QUIT;
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.
« If your CSV file uses a delimiter other than a comma (like a semicolon or pipe), specify it explicitly within importOptions={fileType="csv", delimiter=";"} to avoid data alignment errors. »
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.