The `saswork_table_with_char300` table is created directly in the script via a DATA step with implicit `datalines`.
1 Code Block
CAS Session Management
Explanation : This block initializes a CAS session, assigns all available CASLIBs to the session, and defines a macro variable `workpath` containing the path to the SAS WORK directory. This is essential for managing data between SAS and CAS. The assignment of `caslib _all_` is an administrative action.
Explanation : This DATA step creates the temporary `saswork_table_with_char300` table in the WORK library. It defines three character variables (`a`, `b`, `c`) with initial lengths of 300, 15, and 16 bytes respectively, then inserts three observations. This table will be used to demonstrate VARCHAR conversion in CAS.
Copied!
data saswork_table_with_char300;
length a $ 300 b $ 15 c $ 16;
a='a300'; b='b15' ; c='c16' ;
output;
a='a300300'; b='b151515'; c='c161616';
output;
c='c161616161616161';
b='b15151515151515';
a="a300qzwsxedcrfvtgbyhnujmiklopqazwsxedcrfvtgbyhnujmikolp1234567890123456789012345678901234567890";
output;
run;
Explanation : This procedure displays the metadata of the `saswork_table_with_char300` table, including variable names, types, and lengths. This allows verifying the structure of the SAS table before its transfer to CAS and confirming the lengths of the character variables.
Copied!
proc contents data=saswork_table_with_char300;
title "Contents of WORK.SASWORK_TABLE_WITH_CHAR300";
run;
1
2
PROC CONTENTS
3
DATA=saswork_table_with_char300;
4
title "Contents of WORK.SASWORK_TABLE_WITH_CHAR300";
5
RUN;
6
4 Code Block
PROC CAS (CASLIB Management)
Explanation : This block uses `PROC CAS` to manage a CASLIB named `sas7bdat`. It first attempts to delete this CASLIB if it already exists (`dropCaslib`), then recreates it (`addcaslib`) by pointing it to the SAS WORK directory path (`&workpath`). This step is necessary for CAS to access SAS files stored in the WORK directory. Direct manipulation of CASLIBs is an administrative action.
Explanation : This procedure loads the `saswork_table_with_char300` table (which is saved on disk in the WORK directory as `saswork_table_with_char300.sas7bdat`) into the CAS server under the name `cas_table_with_varchar` in the `casuser` CASLIB. The `varcharconversion=16` option is crucial here: it forces SAS character variables with a length greater than 16 bytes to be converted to VARCHAR type in CAS, allowing for more efficient storage of variable-length character strings and optimizing memory usage in CAS.
Explanation : This last block uses `PROC CAS` to set session options on the `casuser` CASLIB, then calls the CAS action `table.columninfo` to display detailed column metadata for the `cas_table_with_varchar` CAS table. This allows verifying how character variables were handled after VARCHAR conversion, particularly confirming that variables 'a' and 'c' were converted to VARCHAR.
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.