Examples use SASHELP data (iris) and internal table creations via DATA step, loaded into CAS memory.
1 Code Block
PROC CAS / simple.summary
Explanation : This example demonstrates the simplest parameter coercion for a list of parameters. The `table=` parameter normally expects a list with options like `name=`. Here, 'iris' is directly provided as a string, and the CAS server interprets it as the default `name` parameter value. This simplifies the syntax by omitting the braces and the 'name=' key. The `caslib` is specified to ensure the location of the 'iris' table.
Copied!
proc cas;
session casauto;
/* Utilisation avec coercition: 'iris' est coercé en name="iris" */
/* La caslib SASHELP est généralement accessible par défaut. */
simple.summary / table="iris", caslib="SASHELP";
run;
quit;
1
PROC CAS;
2
SESSION casauto;
3
4
/* Utilisation avec coercition: 'iris' est coercé en name="iris" */
5
/* La caslib SASHELP est généralement accessible par défaut. */
6
SIMPLE.summary / TABLE="iris", caslib="SASHELP";
7
RUN;
8
QUIT;
2 Code Block
PROC CAS / dataPreprocess.binning Data
Explanation : This example illustrates coercion for a parameter array, such as the `inputs` parameter of the `binning` action. Instead of specifying `inputs={{name="SepalLength"}, {name="PetalLength"}}`, we can directly list the variable names in a string array (`{"SepalLength", "PetalLength"}`). The CAS server interprets each string as the `name` parameter value for each element of the array. This makes the code more concise and readable. The `iris` table is loaded into `casuser` to ensure the autonomy of the example.
Copied!
proc cas;
session casauto;
/* S'assurer que la caslib 'casuser' existe et est active */
caslib _all_ assign;
/* Charger la table iris dans la caslib 'casuser' pour l'exemple */
proc casutil;
load casdata="iris" incaslib="SASHELP" outcaslib="casuser" replace;
run;
/* Utilisation avec coercition pour le tableau 'inputs' */
dataPreprocess.binning /
table="iris",
caslib="casuser",
inputs={"SepalLength", "PetalLength"};
/* Nettoyage: suppression de la table temporaire */
table.dropTable / name="iris", caslib="casuser";
run;
quit;
1
PROC CAS;
2
SESSION casauto;
3
/* S'assurer que la caslib 'casuser' existe et est active */
4
caslib _all_ assign;
5
6
/* Charger la table iris dans la caslib 'casuser' pour l'exemple */
/* Utilisation avec coercition pour le tableau 'inputs' */
12
dataPreprocess.binning /
13
TABLE="iris",
14
caslib="casuser",
15
inputs={"SepalLength", "PetalLength"};
16
17
/* Nettoyage: suppression de la table temporaire */
18
TABLE.dropTable / name="iris", caslib="casuser";
19
RUN;
20
QUIT;
3 Code Block
PROC CAS / regression.logistic Data
Explanation : This advanced example shows how to combine coerced parameters with full specifications within the same array, using the `class=` parameter often present in statistical actions (here, `regression.logistic`). For the 'var1' variable, only the string is provided (`"var1"`), relying on coercion for `name="var1"`. For 'var2', a full specification is used (`{name="var2", order="FORMATTED"}`) to include an `order` option. This illustrates the flexibility of using the simplest form when possible and the full form when additional options are needed.
Copied!
proc cas;
session casauto;
caslib _all_ assign;
/* Création d'une table d'exemple en mémoire CAS */
data casuser.mydata;
input var1 $ var2 var3;
datalines;
A 10 1
B 20 0
A 15 1
C 25 0
B 12 1
D 30 1
;
run;
/* Exemple d'action utilisant le paramètre 'class' avec coercition partielle */
/* Charger l'actionSet 'regression' si ce n'est pas déjà fait */
builtins.loadActionSet / actionSet="regression";
regression.logistic /
table={name="mydata", caslib="casuser"},
model={target="var3"},
inputs="var2",
class={
"var1", /* Coercition pour name="var1" */
{name="var2", order="FORMATTED"} /* Spécification complète pour var2 avec option */
};
/* Nettoyage de la table */
table.dropTable / name="mydata", caslib="casuser";
run;
quit;
1
PROC CAS;
2
SESSION casauto;
3
caslib _all_ assign;
4
5
/* Création d'une table d'exemple en mémoire CAS */
6
DATA casuser.mydata;
7
INPUT var1 $ var2 var3;
8
DATALINES;
9
A 101
10
B 20 0
11
A 151
12
C 25 0
13
B 121
14
D 301
15
;
16
RUN;
17
18
/* Exemple d'action utilisant le paramètre 'class' avec coercition partielle */
19
/* Charger l'actionSet 'regression' si ce n'est pas déjà fait */
20
BUILTINS.LOADACTIONSET / actionSet="regression";
21
22
regression.logistic /
23
TABLE={name="mydata", caslib="casuser"},
24
model={target="var3"},
25
inputs="var2",
26
class={
27
"var1", /* Coercition pour name="var1" */
28
{name="var2", order="FORMATTED"} /* Spécification complète pour var2 avec option */
Explanation : This example demonstrates coercion when loading a table into CAS. First, a local SAS table (`work.local_data`) is created. Then, the `table.loadtable` action is used to load this table into CAS memory. Here, the `path` value (`"work.local_data"`) is directly provided, with the CAS server coercing it to designate the source. Similarly, the `target` parameter is simplified to `"my_loaded_table"`, with the server interpreting it as `name="my_loaded_table"`. Explicitly using `caslib="casuser"` in the action shows how to target a specific library.
Copied!
proc cas;
session casauto;
/* S'assurer que la caslib 'casuser' existe et est active */
caslib _all_ assign;
/* Créer une table SAS locale pour l'exemple */
data work.local_data;
input id name $;
datalines;
1 Alpha
2 Beta
3 Gamma
;
run;
/* Charger la table locale 'local_data' dans la caslib 'casuser' de CAS */
/* 'path' est coercé, 'target' est coercé */
table.loadtable /
caslib="casuser",
path="work.local_data",
promote=TRUE,
target="my_loaded_table";
/* Afficher les informations de la table chargée */
table.tableInfo / name="my_loaded_table", caslib="casuser";
/* Nettoyage : supprimer la table chargée de CAS */
table.dropTable / name="my_loaded_table", caslib="casuser";
/* Nettoyage : supprimer la table de travail SAS locale */
proc datasets lib=work nolist;
delete local_data;
run; quit;
run;
quit;
1
PROC CAS;
2
SESSION casauto;
3
4
/* S'assurer que la caslib 'casuser' existe et est active */
5
caslib _all_ assign;
6
7
/* Créer une table SAS locale pour l'exemple */
8
DATA work.local_data;
9
INPUT id name $;
10
DATALINES;
11
1 Alpha
12
2 Beta
13
3 Gamma
14
;
15
RUN;
16
17
/* Charger la table locale 'local_data' dans la caslib 'casuser' de CAS */
18
/* 'path' est coercé, 'target' est coercé */
19
TABLE.loadtable /
20
caslib="casuser",
21
path="work.local_data",
22
promote=TRUE,
23
target="my_loaded_table";
24
25
/* Afficher les informations de la table chargée */
/* Nettoyage : supprimer la table de travail SAS locale */
32
PROC DATASETS lib=work nolist;
33
delete local_data;
34
RUN; QUIT;
35
36
RUN;
37
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.
« While coercion makes code concise, it relies on the action's definition of a "default" parameter (usually name). When you are troubleshooting a new or complex CAS action, it is often helpful to revert to the explicit {name="target"} syntax once to ensure the CAS server is mapping your inputs exactly as you intend. »
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.