<?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: Create SQL Server table from SAS program in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Create-SQL-Server-table-from-SAS-program/m-p/844992#M36751</link>
    <description>&lt;P&gt;In that case I suggest you use SQL Passthru to get better control over what SQL Server is doing:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;LIBNAME FA ODBC DSN='XXX_DSN' schema=dbo datasrc="XXX" user=uid password=pwd;

PROC SQL;
connect using FA;
execute(
CREATE TABLE MyServer.Mydatabase.dbo.FA.SM_TEST1 (
ID varchar(12)
) by FA;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 17 Nov 2022 22:20:30 GMT</pubDate>
    <dc:creator>SASKiwi</dc:creator>
    <dc:date>2022-11-17T22:20:30Z</dc:date>
    <item>
      <title>Create SQL Server table from SAS program</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Create-SQL-Server-table-from-SAS-program/m-p/844976#M36748</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am new to SAS programming, trying to create new SQL Server table and then insert data from SAS dataset.&lt;/P&gt;&lt;P&gt;Here are the steps I have used,&lt;/P&gt;&lt;P&gt;1. Create a ODBC data source (Microsoft SQL Server Native Client Version 11.0), as&amp;nbsp;'XXX_DSN'.&lt;/P&gt;&lt;P&gt;2. Below is the SAS program I have used.&lt;/P&gt;&lt;P&gt;LIBNAME FA ODBC DSN='XXX_DSN' schema=dbo datasrc="XXX" user=uid password=pwd;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE FA.SM_TEST1 (&lt;BR /&gt;ID varchar(12)&lt;BR /&gt;);&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I end up getting error as below.&lt;/P&gt;&lt;P&gt;NOTE: SAS variable labels, formats, and lengths are not written to DBMS tables.&lt;BR /&gt;ERROR: Error attempting to CREATE a DBMS table. ERROR: CLI execute error: [Microsoft][SQL Server Native Client 11.0][SQL&lt;BR /&gt;Server]CREATE TABLE permission denied in database 'YYYYDataMart'..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Shirish&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Nov 2022 21:02:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Create-SQL-Server-table-from-SAS-program/m-p/844976#M36748</guid>
      <dc:creator>smallavolu</dc:creator>
      <dc:date>2022-11-17T21:02:05Z</dc:date>
    </item>
    <item>
      <title>Re: Create SQL Server table from SAS program</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Create-SQL-Server-table-from-SAS-program/m-p/844980#M36749</link>
      <description>&lt;P&gt;You don't have the CREATE TABLE permission in the database you are trying to write to. You will need to request this from your SQL Server database administrator.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Nov 2022 21:15:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Create-SQL-Server-table-from-SAS-program/m-p/844980#M36749</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2022-11-17T21:15:28Z</dc:date>
    </item>
    <item>
      <title>Re: Create SQL Server table from SAS program</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Create-SQL-Server-table-from-SAS-program/m-p/844984#M36750</link>
      <description>&lt;P&gt;Thanks SASKiwi.&amp;nbsp;&lt;/P&gt;&lt;P&gt;But, which is used as user mentioned in LIBNAME "uid" as "user=uid" does have rights to create the tables. and I did cross check by creating table SSMS.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Nov 2022 21:27:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Create-SQL-Server-table-from-SAS-program/m-p/844984#M36750</guid>
      <dc:creator>smallavolu</dc:creator>
      <dc:date>2022-11-17T21:27:40Z</dc:date>
    </item>
    <item>
      <title>Re: Create SQL Server table from SAS program</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Create-SQL-Server-table-from-SAS-program/m-p/844992#M36751</link>
      <description>&lt;P&gt;In that case I suggest you use SQL Passthru to get better control over what SQL Server is doing:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;LIBNAME FA ODBC DSN='XXX_DSN' schema=dbo datasrc="XXX" user=uid password=pwd;

PROC SQL;
connect using FA;
execute(
CREATE TABLE MyServer.Mydatabase.dbo.FA.SM_TEST1 (
ID varchar(12)
) by FA;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 17 Nov 2022 22:20:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Create-SQL-Server-table-from-SAS-program/m-p/844992#M36751</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2022-11-17T22:20:30Z</dc:date>
    </item>
    <item>
      <title>Re: Create SQL Server table from SAS program</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Create-SQL-Server-table-from-SAS-program/m-p/844997#M36752</link>
      <description>&lt;P&gt;Thanks, but still no luck.&lt;/P&gt;&lt;P&gt;This time code does not throw any error. But, no table is created.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Nov 2022 23:01:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Create-SQL-Server-table-from-SAS-program/m-p/844997#M36752</guid>
      <dc:creator>smallavolu</dc:creator>
      <dc:date>2022-11-17T23:01:02Z</dc:date>
    </item>
    <item>
      <title>Re: Create SQL Server table from SAS program</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Create-SQL-Server-table-from-SAS-program/m-p/845001#M36753</link>
      <description>&lt;P&gt;Please post the complete SAS log of your program.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;EDIT - there is a missing bracket in the code I posted. Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;LIBNAME FA ODBC DSN='XXX_DSN' schema=dbo datasrc="XXX" user=uid password=pwd;

PROC SQL;
connect using FA;
execute(
CREATE TABLE MyServer.Mydatabase.dbo.FA.SM_TEST1 (
ID varchar(12)
)
) by FA;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 17 Nov 2022 23:12:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Create-SQL-Server-table-from-SAS-program/m-p/845001#M36753</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2022-11-17T23:12:05Z</dc:date>
    </item>
    <item>
      <title>Re: Create SQL Server table from SAS program</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Create-SQL-Server-table-from-SAS-program/m-p/845002#M36754</link>
      <description>&lt;P&gt;I would check the log again, there should be an error if the table is not being created.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can also try:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;LIBNAME FA ODBC DSN='XXX_DSN' schema=dbo datasrc="XXX" user=uid password=pwd;

proc append base=fa.class data=sashelp.class;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Assuming there is no table in your database named class, it should be created, and then the 19 records from sashelp.class should be inserted into it.&amp;nbsp; And if you run it again, it should insert the same 19 records again (so you'll have 38 records).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Agree with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13976"&gt;@SASKiwi&lt;/a&gt;&amp;nbsp; that using explicit pass through is also a great approach.&amp;nbsp; You said you have run the create table code in SQL Server Management Studio and it works?&amp;nbsp; Then you should be able to paste that code into the pass-through shell:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;LIBNAME FA ODBC DSN='XXX_DSN' schema=dbo datasrc="XXX" user=uid password=pwd;

PROC SQL;
connect using FA;
execute(
/*your working SQL code from SSMS here*/
) by FA;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;That first create table permission error is pretty clear.&amp;nbsp; I would double-check that when you connect via SSMS, you are the same user as you pass in the SAS session.&amp;nbsp; And double check your DSN is pointing to the right database.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Wait, after typing all that I just noticed &lt;STRONG&gt;your LIBNAME statement has both DSN= and DATAsrc=&lt;/STRONG&gt;, with different values.&amp;nbsp; DSN is an alias for DATASRC.&amp;nbsp; You don't want both of these.&amp;nbsp; As written, I don't know if you're connecting to XXX_DSN or XXX.&amp;nbsp; The log might tell you.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;LIBNAME FA ODBC DSN='XXX_DSN' schema=dbo datasrc="XXX" user=uid password=pwd;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Nov 2022 23:19:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Create-SQL-Server-table-from-SAS-program/m-p/845002#M36754</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2022-11-17T23:19:28Z</dc:date>
    </item>
    <item>
      <title>Re: Create SQL Server table from SAS program</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Create-SQL-Server-table-from-SAS-program/m-p/845042#M36759</link>
      <description>&lt;P&gt;Yes the missing bracket was the issue. But, surprised the program did not throw any error.&lt;/P&gt;&lt;P&gt;Any I just used&amp;nbsp;MyServer.Mydatabase.dbo.SM_TEST1 .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;One follow-up question, how to use pass thru SQL when we need to use insert or update statements. As how can use SAS datasets in SQL pass thru statements.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Shirish&lt;/P&gt;</description>
      <pubDate>Fri, 18 Nov 2022 06:16:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Create-SQL-Server-table-from-SAS-program/m-p/845042#M36759</guid>
      <dc:creator>smallavolu</dc:creator>
      <dc:date>2022-11-18T06:16:23Z</dc:date>
    </item>
    <item>
      <title>Re: Create SQL Server table from SAS program</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Create-SQL-Server-table-from-SAS-program/m-p/845102#M36781</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/437152"&gt;@smallavolu&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One follow-up question, how to use pass thru SQL when we need to use insert or update statements.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Just like in SSMS.&amp;nbsp; Often I will write SQL code in SSMS and get it working there, then paste it into the pass-thru shell.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;And how can use SAS datasets in SQL pass thru statements.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I'm not quite sure what you mean by this, but I think the answer is "you can't".&amp;nbsp; The point of explicit pass through is that your SQL code runs on SQL server, it is not run in SAS.&amp;nbsp; So your SQL server instance can't read a SAS dataset.&amp;nbsp; One option is to load the data from your SAS dataset to a SQL server table (could be temporary).&amp;nbsp; Then your explicit pass-through SQL code use that table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Nov 2022 13:36:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Create-SQL-Server-table-from-SAS-program/m-p/845102#M36781</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2022-11-18T13:36:25Z</dc:date>
    </item>
    <item>
      <title>Re: Create SQL Server table from SAS program</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Create-SQL-Server-table-from-SAS-program/m-p/845128#M36785</link>
      <description>&lt;P&gt;Thanks Quentin and SASKiwi for all your help and tips.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Nov 2022 15:19:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Create-SQL-Server-table-from-SAS-program/m-p/845128#M36785</guid>
      <dc:creator>smallavolu</dc:creator>
      <dc:date>2022-11-18T15:19:54Z</dc:date>
    </item>
    <item>
      <title>Re: Create SQL Server table from SAS program</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Create-SQL-Server-table-from-SAS-program/m-p/845221#M36794</link>
      <description>&lt;P&gt;When loading SAS datasets I usually use &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/n1hmips60w5w3yn1hj9klna7aplw.htm" target="_blank" rel="noopener"&gt;PROC DATASETS&lt;/A&gt; and the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/n19kwc3onglzh2n1l2k4e39edv3x.htm" target="_blank" rel="noopener"&gt;APPEND&lt;/A&gt; statement as it is simple and efficient. I tend to avoid updates, and see if I can instead use deletes and inserts - this is what APPEND does.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Nov 2022 22:43:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Create-SQL-Server-table-from-SAS-program/m-p/845221#M36794</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2022-11-18T22:43:28Z</dc:date>
    </item>
  </channel>
</rss>

