Hi All,
Could someone give sample code snippet to use bulkload option for SAS/Access interface to Snowflake.
I am able to connect to Snow flake successfully using libname statement.
libname bulk sasiosnf dsn='snowflake_dev' user=xxxxxx
Hi @karthic2612
It just so happens that I am writing an SGF paper on SAS/ACCESS Interface to Snowflake. I am using the following code to test some ideas. Keep in mind, you will need to create STAGES for some of this code to work. Check out the Snowflake DDL doc for details. The S3 example requires a valid bucket.
/* Snowflake SGF Paper - Experiments - Jeff Bailey */
/* Test the various Snowflake load techniques with largish data */
/* 1 GB */
/* Generate non-trivial data from performance experiments */
/* 4.5M = 1 GB */
data work.large_table_1GB;
format dt date.;
do i = 1 to 4500000;
dt = i + 1;
mynum1 = i;
text1 = "abcdefghijklmnopqrstuvwxyz0123456789";
mynum2 = i * 10;
text2 = "abcdefghijklmnopqrstuvwxyz0123456789";
mynum3 = i * 10;
text3 = "abcdefghijklmnopqrstuvwxyz0123456789";
mynum4 = i * 10;
text4 = "abcdefghijklmnopqrstuvwxyz0123456789";
mynum5 = i * 10;
text5 = "abcdefghijklmnopqrstuvwxyz0123456789";
mynum6 = i * 10;
output;
end;
run;
/* If you want to do inserts add INSERT=32000 and DBCOMMIT=0 to LIBNAME statement */
libname snow SNOW server="something.snowflakecomputing.com"
db=TESTDB
warehouse=TESTWH
schema=THISUSER
user=THISUSER
pw=MyPassword123!
preserve_tab_names=no;
/* Get a baseline for performance */
data snow.large_table_1GB;
set large_table_1GB;
run;
options sastrace=',,,d' sastraceloc=saslog nostsuffix;
/* Load via a Snowflake internal named stage */
/* Must create an internal stage in Snowflake (via SQL) for this to work. */
data snow.large_table_1GB_named_stage (bulkload=yes bl_stage="MY_STAGE" BL_COMPRESS=yes);
set large_table_1GB;
run;
/* Load via a Snowflake table stage */
data snow.large_table_1GB_table_stage (bulkload=yes bl_internal_stage="table/sometable" BL_COMPRESS=yes);
set large_table_1GB;
run;
/* Load via a Snowflake user stage */
data snow.large_table_1GB_user_stage (bulkload=yes bl_internal_stage="user/someuser" BL_COMPRESS=yes);
set large_table_1GB;
run;
/* Load via an S3 bucket */
/* Must create an S3 bucket for this to work */
/* Must ssh into the Linux machine where SAS is running and obtain new credentials - kinit, getaswkey */
data snow.large_table_1GB_s3_stage (bulkload=yes bl_bucket="snowbulk-mybucket" bl_compress=yes);
set large_table_1GB;
run;
Good luck,
Jeff
Hi @karthic2612
It just so happens that I am writing an SGF paper on SAS/ACCESS Interface to Snowflake. I am using the following code to test some ideas. Keep in mind, you will need to create STAGES for some of this code to work. Check out the Snowflake DDL doc for details. The S3 example requires a valid bucket.
/* Snowflake SGF Paper - Experiments - Jeff Bailey */
/* Test the various Snowflake load techniques with largish data */
/* 1 GB */
/* Generate non-trivial data from performance experiments */
/* 4.5M = 1 GB */
data work.large_table_1GB;
format dt date.;
do i = 1 to 4500000;
dt = i + 1;
mynum1 = i;
text1 = "abcdefghijklmnopqrstuvwxyz0123456789";
mynum2 = i * 10;
text2 = "abcdefghijklmnopqrstuvwxyz0123456789";
mynum3 = i * 10;
text3 = "abcdefghijklmnopqrstuvwxyz0123456789";
mynum4 = i * 10;
text4 = "abcdefghijklmnopqrstuvwxyz0123456789";
mynum5 = i * 10;
text5 = "abcdefghijklmnopqrstuvwxyz0123456789";
mynum6 = i * 10;
output;
end;
run;
/* If you want to do inserts add INSERT=32000 and DBCOMMIT=0 to LIBNAME statement */
libname snow SNOW server="something.snowflakecomputing.com"
db=TESTDB
warehouse=TESTWH
schema=THISUSER
user=THISUSER
pw=MyPassword123!
preserve_tab_names=no;
/* Get a baseline for performance */
data snow.large_table_1GB;
set large_table_1GB;
run;
options sastrace=',,,d' sastraceloc=saslog nostsuffix;
/* Load via a Snowflake internal named stage */
/* Must create an internal stage in Snowflake (via SQL) for this to work. */
data snow.large_table_1GB_named_stage (bulkload=yes bl_stage="MY_STAGE" BL_COMPRESS=yes);
set large_table_1GB;
run;
/* Load via a Snowflake table stage */
data snow.large_table_1GB_table_stage (bulkload=yes bl_internal_stage="table/sometable" BL_COMPRESS=yes);
set large_table_1GB;
run;
/* Load via a Snowflake user stage */
data snow.large_table_1GB_user_stage (bulkload=yes bl_internal_stage="user/someuser" BL_COMPRESS=yes);
set large_table_1GB;
run;
/* Load via an S3 bucket */
/* Must create an S3 bucket for this to work */
/* Must ssh into the Linux machine where SAS is running and obtain new credentials - kinit, getaswkey */
data snow.large_table_1GB_s3_stage (bulkload=yes bl_bucket="snowbulk-mybucket" bl_compress=yes);
set large_table_1GB;
run;
Good luck,
Jeff
Looking forward to the presentation @JBailey !
But do I undrestand it right, that SAS doesn't set up a Snowflake stage on the fly in the bulk-load process...?
Hi @LinusH,
It depends on the STAGE. Table and User Stages are always present in Snowflake. Internal Named Stages must be created by the DBA, or someone with proper privileges. Configuring S3 as a Stage requires AWS configuration. It is a very interesting topic; I am beginning to write this section of the paper today.
<things_say_every_time_I_write_an_SGF_paper>I swear this is the last SGF paper I will ever write.</things_say_every_time_I_write_an_SGF_paper>
Best wishes,
Jeff
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.