Type : CREATION_INTERNE
Los ejemplos utilizan datos generados (datalines) o SASHELP para crear y promover una biblioteca de formatos directamente dentro de los caslibs.
| 1 | options casopts=(caslib=casuser timeout=900); |
| 2 | cas casauto; |
| 3 | |
| 4 | PROC CAS; |
| 5 | SESSION casauto.addcaslib / caslib='myglobalformats' path='&_TEMP_/myformats' subdirs=true datasource=(srctype='path'); |
| 6 | QUIT; |
| 7 | |
| 8 | PROC FORMAT lib=myglobalformats; |
| 9 | value $genderfmt |
| 10 | 'M' = 'Masculin' |
| 11 | 'F' = 'Féminin'; |
| 12 | value agegrpfmt |
| 13 | low-<18 = 'Mineur' |
| 14 | 18-high = 'Adulte'; |
| 15 | RUN; |
| 16 | |
| 17 | PROC CAS; |
| 18 | SESSION casauto.addFmtSearchPath / searchPath={'myglobalformats'}; |
| 19 | QUIT; |
| 20 | |
| 21 | DATA casuser.clients (promote=yes); |
| 22 | INPUT Name $ Gender $ Age; |
| 23 | FORMAT Gender $genderfmt. Age agegrpfmt.; |
| 24 | DATALINES; |
| 25 | Alice F 25 |
| 26 | Bob M 17 |
| 27 | Carol F 30 |
| 28 | David M 20 |
| 29 | ; |
| 30 | RUN; |
| 31 | |
| 32 | PROC PRINT DATA=casuser.clients; |
| 33 | RUN; |
| 34 | |
| 35 | PROC CAS; |
| 36 | SESSION casauto.removeFmtSearchPath / searchPath={'myglobalformats'}; |
| 37 | SESSION casauto.dropcaslib / caslib='myglobalformats'; |
| 38 | QUIT; |
| 1 | options casopts=(caslib=casuser timeout=900); |
| 2 | cas casauto; |
| 3 | |
| 4 | PROC CAS; |
| 5 | SESSION casauto.addcaslib / caslib='myglobalformats' path='&_TEMP_/myformats' subdirs=true datasource=(srctype='path'); |
| 6 | QUIT; |
| 7 | |
| 8 | PROC FORMAT lib=myglobalformats; |
| 9 | value $statusfmt |
| 10 | 'A' = 'Actif' |
| 11 | 'I' = 'Inactif' |
| 12 | 'X' = 'En attente' |
| 13 | other = 'Inconnu'; |
| 14 | RUN; |
| 15 | |
| 16 | PROC CAS; |
| 17 | SESSION casauto.addFmtSearchPath / searchPath={'myglobalformats'}; |
| 18 | QUIT; |
| 19 | |
| 20 | DATA casuser.ventes (promote=yes); |
| 21 | INPUT Produit $ StatutCommande $ Montant; |
| 22 | FORMAT StatutCommande $statusfmt.; |
| 23 | DATALINES; |
| 24 | PC A 1200 |
| 25 | Souris I 25 |
| 26 | Clavier A 80 |
| 27 | Ecran X 300 |
| 28 | ; |
| 29 | RUN; |
| 30 | |
| 31 | PROC PRINT DATA=casuser.ventes; |
| 32 | RUN; |
| 33 | |
| 34 | PROC CAS; |
| 35 | SESSION casauto.removeFmtSearchPath / searchPath={'myglobalformats'}; |
| 36 | SESSION casauto.dropcaslib / caslib='myglobalformats'; |
| 37 | QUIT; |
| 1 | options casopts=(caslib=casuser timeout=900); |
| 2 | cas casauto; |
| 3 | |
| 4 | PROC CAS; |
| 5 | SESSION casauto.addcaslib / caslib='dynamicformats' path='&_TEMP_/dynamicformats' subdirs=true datasource=(srctype='path'); |
| 6 | QUIT; |
| 7 | |
| 8 | %macro create_and_promote_format(LIBNAME, fmtname); |
| 9 | PROC FORMAT lib=&LIBNAME; |
| 10 | value &fmtname |
| 11 | 1 = 'Faible' |
| 12 | 2 = 'Moyen' |
| 13 | 3 = 'Élevé'; |
| 14 | RUN; |
| 15 | |
| 16 | PROC CAS; |
| 17 | SESSION casauto.addFmtSearchPath / searchPath={'&libname'}; |
| 18 | QUIT; |
| 19 | %mend; |
| 20 | |
| 21 | %create_and_promote_format(LIBNAME=dynamicformats, fmtname=level); |
| 22 | |
| 23 | PROC FORMAT lib=dynamicformats; |
| 24 | value level |
| 25 | 1 = 'Bas' |
| 26 | 2 = 'Moy' |
| 27 | 3 = 'Haut'; |
| 28 | RUN; |
| 29 | |
| 30 | DATA casuser.evaluations; |
| 31 | INPUT ID Niveau; |
| 32 | FORMAT Niveau level.; |
| 33 | DATALINES; |
| 34 | 101 1 |
| 35 | 102 2 |
| 36 | 103 3 |
| 37 | ; |
| 38 | RUN; |
| 39 | |
| 40 | PROC PRINT DATA=casuser.evaluations; |
| 41 | RUN; |
| 42 | |
| 43 | PROC CAS; |
| 44 | SESSION casauto.removeFmtSearchPath / searchPath={'dynamicformats'}; |
| 45 | SESSION casauto.dropcaslib / caslib='dynamicformats'; |
| 46 | QUIT; |
| 1 | options casopts=(caslib=casuser timeout=900); |
| 2 | cas casauto; |
| 3 | |
| 4 | PROC CAS; |
| 5 | SESSION casauto.addcaslib / caslib='temp_formats' path='&_TEMP_/temp_formats' subdirs=true datasource=(srctype='path'); |
| 6 | QUIT; |
| 7 | |
| 8 | PROC FORMAT lib=temp_formats; |
| 9 | value $yesnofmt |
| 10 | 'Y' = 'Oui' |
| 11 | 'N' = 'Non'; |
| 12 | RUN; |
| 13 | |
| 14 | PROC CAS; |
| 15 | SESSION casauto.addFmtSearchPath / searchPath={'temp_formats'}; |
| 16 | QUIT; |
| 17 | |
| 18 | PROC CAS; |
| 19 | SESSION casauto.listFmtSearchPath; |
| 20 | QUIT; |
| 21 | |
| 22 | DATA casuser.sondage; |
| 23 | INPUT Question $ Reponse $; |
| 24 | FORMAT Reponse $yesnofmt.; |
| 25 | DATALINES; |
| 26 | Q1 Y |
| 27 | Q2 N |
| 28 | ; |
| 29 | RUN; |
| 30 | |
| 31 | PROC PRINT DATA=casuser.sondage; |
| 32 | RUN; |
| 33 | |
| 34 | PROC CAS; |
| 35 | SESSION casauto.removeFmtSearchPath / searchPath={'temp_formats'}; |
| 36 | QUIT; |
| 37 | |
| 38 | PROC CAS; |
| 39 | SESSION casauto.listFmtSearchPath; |
| 40 | QUIT; |
| 41 | |
| 42 | PROC CAS; |
| 43 | SESSION casauto.dropcaslib / caslib='temp_formats' _all_=true; |
| 44 | QUIT; |