The source table `ts_STRING` is programmatically created by the script in the `mydblib` library, which is itself a connection to an external DBMS. The tables `mydblibsas` and `ysas` are then created from `ts_STRING` within the same external DBMS.
1 Code Block
PROC DELETE
Explanation : This block deletes the temporary tables (`ts_STRING`, `mydblibsas`, `ysas`) from the `mydblib` library if they exist, thus ensuring a clean environment for script execution.
Explanation : This `DATA STEP` block creates a table named `ts_STRING` in the `mydblib` library. This table contains a single column `ts` that stores the current date and time, formatted with a precision of 25.6 characters.
Copied!
data mydblib.ts_STRING;
format ts datetime25.6;
ts=datetime();
run;
1
DATA mydblib.ts_STRING;
2
FORMAT ts datetime25.6;
3
ts=datetime();
4
RUN;
3 Code Block
PROC SQL Data
Explanation : This segment uses `PROC SQL` to establish a connection to an external DBMS (specified by the `&dbms` and `&CONNOPT` macros). It then executes a 'Create Table As Select' (CTAS) operation to create a new table `mydblibsas` in the `mydblib` library, selecting all data from the `ts_STRING` table via the database connection. `sastrace` options are enabled for debugging. Finally, a `DATA _NULL_` is used to display the contents of the new `mydblibsas` table in the SAS log.
Copied!
option sastrace=',,,d' sastraceloc=saslog nostsuffix;
proc sql;
connect to &dbms(&CONNOPT);
create table mydblibsas as select * from connection to &dbms(
SELECT ts FROM ts_STRING
);
quit;
option sastrace=',,,' sastraceloc=saslog nostsuffix;
data _null_; set mydblibsas; put _all_; run;
Explanation : This block is similar to the previous one, but it demonstrates an explicit specification of the read method. It uses `PROC SQL` for a CTAS operation, creating the `ysas` table in `mydblib`. The key difference is the inclusion of `READ_METHOD=JDBC` in the DBMS connection string, forcing the use of the JDBC driver for data access. The content of `ysas` is then displayed in the SAS log for verification.
Copied!
option sastrace=',,,d' sastraceloc=saslog nostsuffix;
proc sql;
connect to &dbms(&CONNOPT READ_METHOD=JDBC);
create table ysas as select * from connection to &dbms(
SELECT ts FROM ts_STRING
);
quit;
option sastrace=',,,' sastraceloc=saslog nostsuffix;
data _null_; set ysas; put _all_; 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.