<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Efficient way to create table in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Efficient-way-to-create-table/m-p/860877#M340058</link>
    <description>&lt;P&gt;If you just need the distinct list of rows on the SAS side and you've got a libname defined then code as below would do the job as well.&lt;/P&gt;
&lt;PRE&gt;options sastrace=',,,d' sastraceloc=saslog nostsuffix;
LIBNAME &amp;lt;libref&amp;gt; snow &amp;lt;connection-options&amp;gt; &amp;lt;LIBNAME-options&amp;gt;;

proc sql noprint;  
  select distinct &amp;amp;current_distinct_var_list
  from &amp;lt;libref&amp;gt;.&amp;amp;source_tbl
  ;
quit;
&lt;/PRE&gt;
&lt;P&gt;SAS will attempt to push as much of the processing as possible to the database.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The options set in the sample code above will show you in the SAS log what has been pushed to the database.&lt;/P&gt;
&lt;P&gt;As long as you don't use SAS functions that SAS can't translate into database functions the whole SQL will run in snowflake.&lt;/P&gt;
&lt;P&gt;Which functions SAS can push to the database is documented &lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/acreldb/n1d5j8d7wegfezn1irjj3hcrne1n.htm" target="_self"&gt;here&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 26 Feb 2023 00:27:21 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2023-02-26T00:27:21Z</dc:date>
    <item>
      <title>Efficient way to create table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Efficient-way-to-create-table/m-p/860862#M340053</link>
      <description>&lt;P&gt;Is there any better method other than shown below 'select distinct' method to create table in database from SAS? I tried proc summary but it's&amp;nbsp;&amp;nbsp;failing on some of the larger tables&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%macro test_loop(
  type_list = 
);  
  proc sql noprint;  
    connect using &amp;amp;db_lib as _snow_temp;

      execute(
        create or replace table &amp;amp;schema_temp..&amp;amp;prompt_tbl_name as
          select distinct &amp;amp;current_distinct_var_list
          from &amp;amp;schema_temp..&amp;amp;source_tbl
        ;
      ) by _snow_temp;
            
      create table DATA.&amp;amp;prompt_table_name as
        select * from connection to _snow_temp (
          select *
          from &amp;amp;schema_temp..&amp;amp;prompt_tbl_name;
        )
      ;
      
    %end;    
  quit;
%mend test_loop;

%let type_list =   
  product_family*upn 
  product_family*region 
  plant_id*batch 
  batch*region 
  batch*event_region  
;
%test_loop(
  type_list = &amp;amp;type_list
)&lt;/PRE&gt;</description>
      <pubDate>Sat, 25 Feb 2023 18:17:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Efficient-way-to-create-table/m-p/860862#M340053</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2023-02-25T18:17:55Z</dc:date>
    </item>
    <item>
      <title>Re: Efficient way to create table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Efficient-way-to-create-table/m-p/860863#M340054</link>
      <description>&lt;P&gt;Do you actually need to create both a SNOWFLAKE table&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;create or replace table &amp;amp;schema_temp..&amp;amp;prompt_tbl_name &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and a SAS dataset?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;create table DATA.&amp;amp;prompt_table_name as&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you only want to create the dataset then skip the step to create the table and just use that query in the second step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;      create table DATA.&amp;amp;prompt_table_name as
        select * from connection to _snow_temp (
          select distinct &amp;amp;current_distinct_var_list
          from &amp;amp;schema_temp..&amp;amp;source_tbl
        )
      ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 25 Feb 2023 18:26:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Efficient-way-to-create-table/m-p/860863#M340054</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-02-25T18:26:08Z</dc:date>
    </item>
    <item>
      <title>Re: Efficient way to create table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Efficient-way-to-create-table/m-p/860877#M340058</link>
      <description>&lt;P&gt;If you just need the distinct list of rows on the SAS side and you've got a libname defined then code as below would do the job as well.&lt;/P&gt;
&lt;PRE&gt;options sastrace=',,,d' sastraceloc=saslog nostsuffix;
LIBNAME &amp;lt;libref&amp;gt; snow &amp;lt;connection-options&amp;gt; &amp;lt;LIBNAME-options&amp;gt;;

proc sql noprint;  
  select distinct &amp;amp;current_distinct_var_list
  from &amp;lt;libref&amp;gt;.&amp;amp;source_tbl
  ;
quit;
&lt;/PRE&gt;
&lt;P&gt;SAS will attempt to push as much of the processing as possible to the database.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The options set in the sample code above will show you in the SAS log what has been pushed to the database.&lt;/P&gt;
&lt;P&gt;As long as you don't use SAS functions that SAS can't translate into database functions the whole SQL will run in snowflake.&lt;/P&gt;
&lt;P&gt;Which functions SAS can push to the database is documented &lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/acreldb/n1d5j8d7wegfezn1irjj3hcrne1n.htm" target="_self"&gt;here&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 26 Feb 2023 00:27:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Efficient-way-to-create-table/m-p/860877#M340058</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-02-26T00:27:21Z</dc:date>
    </item>
    <item>
      <title>Re: Efficient way to create table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Efficient-way-to-create-table/m-p/860882#M340060</link>
      <description>Yes, I was asked to create the tables as shown in initial post.&lt;BR /&gt;&lt;BR /&gt;However I'd like to seek your help to improve the code further with any&lt;BR /&gt;efficient method available.&lt;BR /&gt;</description>
      <pubDate>Sun, 26 Feb 2023 01:28:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Efficient-way-to-create-table/m-p/860882#M340060</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2023-02-26T01:28:50Z</dc:date>
    </item>
    <item>
      <title>Re: Efficient way to create table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Efficient-way-to-create-table/m-p/860883#M340061</link>
      <description>&lt;P&gt;The code portion that creates the table in snowflake is 100% Snowflake SQL. If you believe that doesn't perform good enough then you need to consult the Snowflake documentation or ask a question in a Snowflake forum.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For loading data from a database to SAS there are normally three things you can look into to improve elapsed times.&lt;/P&gt;
&lt;P&gt;1. Setting of SAS library parameter readbuff (default is almost always too low)&lt;/P&gt;
&lt;P&gt;2. Database starting to send the data before the query completes (that's a database setting so Snowflake docu/forum; not sure what's applicable for Snowflake)&lt;/P&gt;
&lt;P&gt;3. Increase parallelism (that's again fully on the database side so&amp;nbsp;Snowflake docu/forum; given it's Snowflake likely already set "optimal").&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Additionally (and not sure what applies to Snowflake) you could also look into "dirty reading" (uncommited read) and if commited read how many times you commit (look also into SAS options for autocommit and libname option dbcommit). Less commits will improve performance as long as you can be confident that there aren't write operations happening on the table while you're reading.&lt;/P&gt;</description>
      <pubDate>Sun, 26 Feb 2023 02:01:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Efficient-way-to-create-table/m-p/860883#M340061</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-02-26T02:01:27Z</dc:date>
    </item>
    <item>
      <title>Re: Efficient way to create table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Efficient-way-to-create-table/m-p/860884#M340062</link>
      <description>Thank you for the information. How to set the parameter read buff?&lt;BR /&gt;</description>
      <pubDate>Sun, 26 Feb 2023 02:02:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Efficient-way-to-create-table/m-p/860884#M340062</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2023-02-26T02:02:50Z</dc:date>
    </item>
    <item>
      <title>Re: Efficient way to create table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Efficient-way-to-create-table/m-p/860885#M340063</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thank you for the information. How to set the parameter read buff?&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/acreldb/p1wimq26x0fumsn12vxzxbgufmww.htm" target="_self"&gt;Data Set Options for Snowflake&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/acreldb/p1se2m9js4ptfpn1252otv84u9ma.htm" target="_self"&gt;LIBNAME Statement for the Snowflake Engine&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could also try Proc Append for loading the data to SAS. Depending where the bottleneck is this could improve elapsed time.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And you could also try bulkload to SAS. This might - or might not - improve elapsed time. You will only know by trying.&lt;/P&gt;</description>
      <pubDate>Sun, 26 Feb 2023 02:12:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Efficient-way-to-create-table/m-p/860885#M340063</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-02-26T02:12:00Z</dc:date>
    </item>
    <item>
      <title>Re: Efficient way to create table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Efficient-way-to-create-table/m-p/860947#M340089</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;any simple example to bulk load to SAS?&lt;/P&gt;</description>
      <pubDate>Sun, 26 Feb 2023 16:28:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Efficient-way-to-create-table/m-p/860947#M340089</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2023-02-26T16:28:43Z</dc:date>
    </item>
    <item>
      <title>Re: Efficient way to create table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Efficient-way-to-create-table/m-p/860953#M340090</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;any simple example to bulk load to SAS?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Not sure about Snowflake but with Redshift I found it faster to use their COPY command that could create multiple delimited text files to an S3 bucket.&amp;nbsp; This allowed the database to generate the files very quickly.&amp;nbsp; I could then copy the files to some place that was local to the SAS server and use a simple data step to read them in.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code to read in a series of delimited text files when you have an example of the known structure is very simple.&amp;nbsp; Define the variables (in the right ORDER!), read the list of filenames, for each filename read the observations from that file.&lt;/P&gt;
&lt;P&gt;So if you have an existing dataset with the variables defined properly, say it is named TEMPLATE, and a dataset named FILELIST with a variable named FILENAME&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  if 0 then set template;
  set filelist;
  do while(not eof);
      infile dummy filevar=filename dsd truncover firstobs=1 end=eof;
      input (_all_) (+0);
      output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Here is an example you can run to see how it works in action:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename csv temp;
data _null_;
  set sashelp.class ;
  file csv dsd ;
  put (_all_) (+0);
run;

data filelist;
  filename=pathname('csv');
run;

data want;
  if 0 then set sashelp.class;
  set filelist;
  infile dummy filevar=filename dsd truncover firstobs=1 end=eof;
  do while (not eof);
    input (_all_) (+0);
    output;
  end;
run;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 26 Feb 2023 17:24:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Efficient-way-to-create-table/m-p/860953#M340090</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-02-26T17:24:00Z</dc:date>
    </item>
    <item>
      <title>Re: Efficient way to create table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Efficient-way-to-create-table/m-p/860957#M340093</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;&amp;nbsp; - SAS doesn't have bulk load functionality like a relational database. Reading external files produced by a relational database into SAS via a DATA step would be an equivalent process.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also I suggest you try the DBCOMMIT option on your LIBNAME or CONNECT statements when creating Snowflake tables. This option can greatly improve table load times when you have a lot of data.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Feb 2023 00:21:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Efficient-way-to-create-table/m-p/860957#M340093</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2023-02-27T00:21:26Z</dc:date>
    </item>
    <item>
      <title>Re: Efficient way to create table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Efficient-way-to-create-table/m-p/861008#M340115</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;any simple example to bulk load to SAS?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Ideally do some search. There are whitepapers and sample code out there that much better explain it than I could.&lt;/P&gt;
&lt;P&gt;You might need additional bulkload options that are documented under the link already provided but in a nutshell it's:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc append data=source base=target(bulkload=yes);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 27 Feb 2023 06:53:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Efficient-way-to-create-table/m-p/861008#M340115</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-02-27T06:53:36Z</dc:date>
    </item>
  </channel>
</rss>

