<?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: Execute statement for MS SQL Server in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Execute-statement-for-MS-SQL-Server/m-p/539827#M148822</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/214996"&gt;@monona&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You don't specify a schema dbo here:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;   connect to odbc as db (required="driver=sql server native client 11.0;
							 	    server=MYSERVER;
								    Trusted_Connection=Yes;
								    Database=MYDB;");&lt;/PRE&gt;
&lt;P&gt;But you specify dbo here:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;libname db odbc noprompt = "server=MYSERVER;DRIVER=SQL Server Native Client 11.0;Trusted_Connection=yes" &lt;BR /&gt;DATABASE = MYDB schema = dbo;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Given that the Proc Append as such appears to work: Are you sure you're looking in the correct schema for the table with data?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;May be also add the following options before your Proc Append statement which will give you a bit more info in the SAS log of what's happening.&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;options sastrace=',,,d' sastraceloc=saslog&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;nostsuffix&lt;/EM&gt;&lt;SPAN&gt;;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Sat, 02 Mar 2019 01:18:28 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2019-03-02T01:18:28Z</dc:date>
    <item>
      <title>Execute statement for MS SQL Server</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Execute-statement-for-MS-SQL-Server/m-p/539778#M148791</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/27614i2B643EF1B15D3B00/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hello. I made a connection to ms sql server, successfully set up a table using execute statement, and this directly updated to the ms sql server.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now, I would like to insert sas dataset( let say work.abc) into there (columns attribute are exactly like that:chr, bp, beta, p_value,trait). How can I do that?&lt;/P&gt;</description>
      <pubDate>Fri, 01 Mar 2019 21:59:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Execute-statement-for-MS-SQL-Server/m-p/539778#M148791</guid>
      <dc:creator>monona</dc:creator>
      <dc:date>2019-03-01T21:59:19Z</dc:date>
    </item>
    <item>
      <title>Re: Execute statement for MS SQL Server</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Execute-statement-for-MS-SQL-Server/m-p/539786#M148797</link>
      <description>&lt;P&gt;Use a Libname Statement to create another connection,&amp;nbsp; It looks like you are writing to a dbo schema.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; Libname dbo odbc Required='....' schema=dbo;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Then a Proc Append (The Data Set will not work, because it will want to delete the current table)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; Proc Append base=dbo.ukbb_statin data=[your table] [other options as needed];&lt;BR /&gt;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;you need to get the data over there somehow, and this seems the cleanest to me.&lt;/P&gt;&lt;P&gt;That last Execute statement will not be used.&amp;nbsp;I would try just&amp;nbsp;the Libname and Proc Append,, and see if the table is created by SAS.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Good Luck&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Mike&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Mar 2019 22:23:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Execute-statement-for-MS-SQL-Server/m-p/539786#M148797</guid>
      <dc:creator>mwhitaker</dc:creator>
      <dc:date>2019-03-01T22:23:41Z</dc:date>
    </item>
    <item>
      <title>Re: Execute statement for MS SQL Server</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Execute-statement-for-MS-SQL-Server/m-p/539788#M148798</link>
      <description>&lt;P&gt;You can't use the EXECUTE statement to directly load SAS tables as SAS data isn't available within SQL Server. I find PROC DATASETS works well. BTW SQL Server will create the BASE table if it doesn't already exist. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname sqlsrvr ODBC noprompt="&amp;lt;put your connection string here&amp;gt;";

proc datasets library = sqlsrvr;
  append base = sqlsrvr.MyTable data = work.MySASTable;
run;
quit; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Mar 2019 22:27:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Execute-statement-for-MS-SQL-Server/m-p/539788#M148798</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2019-03-01T22:27:45Z</dc:date>
    </item>
    <item>
      <title>Re: Execute statement for MS SQL Server</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Execute-statement-for-MS-SQL-Server/m-p/539800#M148804</link>
      <description>&lt;P&gt;Hello, this works without error and generated a table under the connected library, but this doesn't push to sql server. I am attaching my code below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
   connect to odbc as db (required="driver=sql server native client 11.0;
							 	    seerver=MYSERVER;
								    Trusted_Connection=Yes;
								    Database=MYDB;");

	execute(drop table mvp_lipid) by db;
	execute(create table mvp_lipid (
		    chr varchar(2),
		    bp numeric(18),
		    beta float,
		    p_value float,
		    trait varchar(20) 
			)) by db;
quit;


libname db odbc noprompt = "server=MYSERVER;DRIVER=SQL Server Native Client 11.0;Trusted_Connection=yes" DATABASE = MYDB schema = dbo;

proc datasets library = db;
	append base = db.mvp_lipid data=sasdata.mvp_lipid;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 01 Mar 2019 23:07:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Execute-statement-for-MS-SQL-Server/m-p/539800#M148804</guid>
      <dc:creator>monona</dc:creator>
      <dc:date>2019-03-01T23:07:41Z</dc:date>
    </item>
    <item>
      <title>Re: Execute statement for MS SQL Server</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Execute-statement-for-MS-SQL-Server/m-p/539806#M148810</link>
      <description>&lt;P&gt;Try this. If it works and prints 10 rows of output then SAS has created an SQL Server table not where you are expecting.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc print data = db.mvp_lipid (obs = 10);
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>Fri, 01 Mar 2019 23:36:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Execute-statement-for-MS-SQL-Server/m-p/539806#M148810</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2019-03-01T23:36:30Z</dc:date>
    </item>
    <item>
      <title>Re: Execute statement for MS SQL Server</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Execute-statement-for-MS-SQL-Server/m-p/539820#M148816</link>
      <description>&lt;P&gt;Your code does work, and db.mvp_lipd has created in SAS, &lt;STRONG&gt;but that doesn't affect ms sql server...T_T&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 458px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/27617i5691CA60251F1B52/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;The empty mvp_lipid shown in sql server is created by the following code.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
   connect to odbc as db (required="driver=sql server native client 11.0;
							 	    server=MYSERVER;
								    Trusted_Connection=Yes;
								    Database=MYDB;");

	execute(drop table mvp_lipid) by db;
	execute(create table mvp_lipid (
		    chr varchar(2),
		    bp numeric(18),
		    beta float,
		    p_value float,
		    trait varchar(20) 
			)) by db;
	
	disconnect from db;   
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 02 Mar 2019 00:59:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Execute-statement-for-MS-SQL-Server/m-p/539820#M148816</guid>
      <dc:creator>monona</dc:creator>
      <dc:date>2019-03-02T00:59:28Z</dc:date>
    </item>
    <item>
      <title>Re: Execute statement for MS SQL Server</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Execute-statement-for-MS-SQL-Server/m-p/539821#M148817</link>
      <description>&lt;P&gt;The DB libref points to an SQL Server table somewhere as the PROC PRINT worked. The question is where is the "DB" table hiding??&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try this in SQL Server Management Studio:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select * from [MYDB].[dbo].[mvp_lipid]&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 02 Mar 2019 01:08:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Execute-statement-for-MS-SQL-Server/m-p/539821#M148817</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2019-03-02T01:08:39Z</dc:date>
    </item>
    <item>
      <title>Re: Execute statement for MS SQL Server</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Execute-statement-for-MS-SQL-Server/m-p/539823#M148818</link>
      <description>&lt;P&gt;My question is why this is reflected to sql server, BUT the second chunk is not relfected.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
   connect to odbc as db (required="driver=sql server native client 11.0;
							 	    server=MYSERVER;
								    Trusted_Connection=Yes;
								    Database=MYDB;");

	execute(drop table mvp_lipid) by db;
	execute(create table mvp_lipid (
		    chr varchar(2),
		    bp numeric(18),
		    beta float,
		    p_value float,
		    trait varchar(20) 
			)) by db;
	
	disconnect from db;   
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname db odbc noprompt = "server=MYSERVER;DRIVER=SQL Server Native Client 11.0;Trusted_Connection=yes" DATABASE = MYDB schema = dbo;

proc datasets library = db;
	append base = db.ukbb_statin data=sasdata.ukbb_statin;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 02 Mar 2019 01:08:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Execute-statement-for-MS-SQL-Server/m-p/539823#M148818</guid>
      <dc:creator>monona</dc:creator>
      <dc:date>2019-03-02T01:08:53Z</dc:date>
    </item>
    <item>
      <title>Re: Execute statement for MS SQL Server</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Execute-statement-for-MS-SQL-Server/m-p/539825#M148820</link>
      <description>same result as shown above. Empty.</description>
      <pubDate>Sat, 02 Mar 2019 01:15:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Execute-statement-for-MS-SQL-Server/m-p/539825#M148820</guid>
      <dc:creator>monona</dc:creator>
      <dc:date>2019-03-02T01:15:55Z</dc:date>
    </item>
    <item>
      <title>Re: Execute statement for MS SQL Server</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Execute-statement-for-MS-SQL-Server/m-p/539826#M148821</link>
      <description>&lt;P&gt;My question is simply why the second chunk of code(about proc append) doesn't create any table in the corresponding table at ms sql server, but the first one does.&lt;/P&gt;</description>
      <pubDate>Sat, 02 Mar 2019 01:16:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Execute-statement-for-MS-SQL-Server/m-p/539826#M148821</guid>
      <dc:creator>monona</dc:creator>
      <dc:date>2019-03-02T01:16:51Z</dc:date>
    </item>
    <item>
      <title>Re: Execute statement for MS SQL Server</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Execute-statement-for-MS-SQL-Server/m-p/539827#M148822</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/214996"&gt;@monona&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You don't specify a schema dbo here:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;   connect to odbc as db (required="driver=sql server native client 11.0;
							 	    server=MYSERVER;
								    Trusted_Connection=Yes;
								    Database=MYDB;");&lt;/PRE&gt;
&lt;P&gt;But you specify dbo here:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;libname db odbc noprompt = "server=MYSERVER;DRIVER=SQL Server Native Client 11.0;Trusted_Connection=yes" &lt;BR /&gt;DATABASE = MYDB schema = dbo;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Given that the Proc Append as such appears to work: Are you sure you're looking in the correct schema for the table with data?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;May be also add the following options before your Proc Append statement which will give you a bit more info in the SAS log of what's happening.&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;options sastrace=',,,d' sastraceloc=saslog&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;nostsuffix&lt;/EM&gt;&lt;SPAN&gt;;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 02 Mar 2019 01:18:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Execute-statement-for-MS-SQL-Server/m-p/539827#M148822</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-03-02T01:18:28Z</dc:date>
    </item>
    <item>
      <title>Re: Execute statement for MS SQL Server</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Execute-statement-for-MS-SQL-Server/m-p/539828#M148823</link>
      <description>my problem is&lt;BR /&gt;&lt;BR /&gt;libname db odbc noprompt = "server=MYSERVER;DRIVER=SQL Server Native Client 11.0;Trusted_Connection=yes"&lt;BR /&gt;DATABASE = MYDB schema = dbo;&lt;BR /&gt;&lt;BR /&gt;this doesn't work but the first one works....TT</description>
      <pubDate>Sat, 02 Mar 2019 03:13:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Execute-statement-for-MS-SQL-Server/m-p/539828#M148823</guid>
      <dc:creator>monona</dc:creator>
      <dc:date>2019-03-02T03:13:47Z</dc:date>
    </item>
    <item>
      <title>Re: Execute statement for MS SQL Server</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Execute-statement-for-MS-SQL-Server/m-p/539834#M148825</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/214996"&gt;@monona&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your explicit pass-through SQL statement runs fully in-database and creates a table.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The Proc Append loads data from SAS to a database so that's involves also a data transfer.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does "not work" mean you get an error in the SAS log or does it mean you don't see data in the SQL table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;From what you wrote so far I understood that the Proc Append executes without errors. If so then the code highly likely loads data into the database - and it also creates the table if it doesn't exist already.&lt;/P&gt;
&lt;P&gt;So.... Given that you don't use an explicit schema name for the connection of the pass-through SQL: Are you really sure that the default schema is DBO which you're using for the libname statement? And are you really sure that you're looking in schema DBO when checking if data has been loaded into the database? Or are you looking in the default schema where you've created the table structure only?&lt;/P&gt;</description>
      <pubDate>Sat, 02 Mar 2019 07:01:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Execute-statement-for-MS-SQL-Server/m-p/539834#M148825</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-03-02T07:01:35Z</dc:date>
    </item>
  </channel>
</rss>

