The script uses the SASHELP.CARS dataset, an internal SAS data source, for the initial data creation. Temporary datasets ('cars') and CAS datasets ('casuser.cars_cas') are created internally and used to apply the formats.
1 Code Block
CASL
Explanation : This block initializes a Cloud Analytic Services (CAS) session and assigns all available caslibs, allowing access to CAS data and resources. It then lists all currently loaded CAS format libraries, providing an overview of the initial state of the formats.
Copied!
cas;
caslib _all_ assign;
cas casauto listformats;
1
cas;
2
caslib _all_ assign;
3
4
cas casauto listformats;
2 Code Block
DATA STEP Data
Explanation : Creates a temporary dataset named 'cars' in the WORK library from the SASHELP.CARS dataset. This dataset will subsequently be used to create formats and CAS tables.
Copied!
data cars;
set sashelp.cars;
run;
1
DATA cars;
2
SET sashelp.cars;
3
RUN;
3 Code Block
PROC FORMAT
Explanation : This block defines a user-defined format 'enginesize' in the WORK.FORMATS library. Thanks to the `casfmtlib="casformats"` option, a copy of this format is automatically created and added to a new CAS format library named 'casformats'. This format categorizes engine sizes into different descriptive categories.
PROC FORMAT library=work.formats casfmtlib="casformats" ;
2
value enginesize
3
low - <2.7 = "Very economical"
4
2.7 - <4.1 = "Small"
5
4.1 - <5.5 = "Medium"
6
5.5 - <6.9 = "Large"
7
6.9 - high = "Very large";
8
RUN;
4 Code Block
CASL
Explanation : Lists the CAS format libraries again to confirm the creation of the 'casformats' library following the execution of PROC FORMAT.
Copied!
cas casauto listformats;
1
cas casauto listformats;
5 Code Block
CASL
Explanation : Promotes the 'casformats' format library to make it global and persistent in CAS memory. This allows other CAS users or sessions to access this format without having to redefine it.
Copied!
cas casauto promotefmtlib fmtlibname='casformats';
1
cas casauto promotefmtlib fmtlibname='casformats';
6 Code Block
CASL
Explanation : Lists the format libraries after promotion to check the status of the 'casformats' library (it should appear as promoted).
Copied!
cas casauto listformats;
1
cas casauto listformats;
7 Code Block
CASL
Explanation : Saves the 'casformats' format library to a SASHDAT file named 'casfmt_table' within the 'formats' caslib. This operation ensures the persistence of the format beyond CAS server restarts.
Copied!
cas casauto savefmtlib fmtlibname='casformats' caslib='formats' table='casfmt_table' replace;
1
cas casauto savefmtlib fmtlibname='casformats' caslib='formats'TABLE='casfmt_table' replace;
2
8 Code Block
PROC CASUTIL
Explanation : Uses PROC CASUTIL to list the files present in the 'formats' caslib and confirm that the SASHDAT file 'casfmt_table' containing the formats has indeed been created and is accessible.
Copied!
proc casutil incaslib='formats';
list files;
quit;
1
2
PROC CASUTIL incaslib='formats';
3
list files;
4
QUIT;
5
9 Code Block
DATA STEP Data
Explanation : Creates a CAS dataset named 'cars_cas' in the 'casuser' caslib from SASHELP.CARS, and applies the 'enginesize' format to the 'EngineSize' variable. The block then displays the first 10 observations of the new dataset to verify the correct application of the CAS format.
Copied!
DATA casuser.cars_cas(replace=yes);
set sashelp.cars;
format enginesize enginesize.;
run;
proc print data=casuser.cars_cas(obs=10);
var EngineSize;
run;
1
DATA casuser.cars_cas(replace=yes);
2
SET sashelp.cars;
3
FORMAT enginesize enginesize.;
4
RUN;
5
6
PROC PRINTDATA=casuser.cars_cas(obs=10);
7
var EngineSize;
8
RUN;
10 Code Block
CASL
Explanation : Lists the CAS format libraries again for a status update after format usage.
Copied!
cas casauto listformats;
1
cas casauto listformats;
11 Code Block
CASL
Explanation : Deletes the 'CASFORMATS' format library from the active CAS session. The `fmtsearchremove` option ensures it is also removed from format search paths.
Copied!
cas casauto dropfmtlib fmtlibname=CASFORMATS fmtsearchremove;
1
cas casauto dropfmtlib fmtlibname=CASFORMATS fmtsearchremove;
2
12 Code Block
CASL
Explanation : Lists the CAS format libraries to confirm that 'CASFORMATS' has been removed from the session.
Copied!
cas casauto listformats;
1
cas casauto listformats;
13 Code Block
CASL
Explanation : Attempts to delete the 'CASFORMATS' format library again. The original code comment indicates that a warning message may appear if the library is no longer found, but this command aims to ensure it is thoroughly removed from any context.
Copied!
cas casauto dropfmtlib fmtlibname=CASFORMATS fmtsearchremove;
1
cas casauto dropfmtlib fmtlibname=CASFORMATS fmtsearchremove;
2
14 Code Block
CASL
Explanation : Lists the CAS format libraries to check the result of the global deletion attempt.
Copied!
cas casauto listformats;
1
cas casauto listformats;
15 Code Block
CASL
Explanation : Loads a format library from the SASHDAT file 'casfmt_table' (previously saved) and makes it available under the new name 'fmthdat' in the CAS session.
Copied!
cas casauto addfmtlib fmtlibname=fmthdat
caslib=formats
table=casfmt_table;
1
cas casauto addfmtlib fmtlibname=fmthdat
2
caslib=formats
3
TABLE=casfmt_table;
4
16 Code Block
CASL
Explanation : Lists the CAS format libraries to confirm the loading of 'fmthdat'.
Copied!
cas casauto listformats;
1
cas casauto listformats;
17 Code Block
CASL
Explanation : Displays the members (individual formats) of all loaded format libraries, then specifically lists the value ranges and labels defined for the 'enginesize' format, validating its content and availability.
Copied!
cas casauto listformats members;
cas casauto listfmtranges fmtname=enginesize;
1
cas casauto listformats members;
2
cas casauto listfmtranges fmtname=enginesize;
3
18 Code Block
DATA STEP Data
Explanation : Recreates the CAS dataset 'cars_cas' using the 'enginesize' format that was reloaded from the SASHDAT file, demonstrating that the format is again active and usable after loading from persistent storage.
Copied!
DATA casuser.cars_cas(replace=yes);
set sashelp.cars;
format enginesize enginesize.;
run;
1
DATA casuser.cars_cas(replace=yes);
2
SET sashelp.cars;
3
FORMAT enginesize enginesize.;
4
RUN;
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.
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.