<?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: Manipulating Data with the SQL Pass-Through Facility (delete obs)? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Manipulating-Data-with-the-SQL-Pass-Through-Facility-delete-obs/m-p/547954#M151901</link>
    <description>&lt;P&gt;perhaps something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;delete a.* 
FROM 
	[my_db].[dbo].[my_large_table] a
	INNER JOIN [my_db].[dbo].[my_small_del_table] b ON a.strm = b.strm and a.emplid = b.emplid and a.snap_date = b.snap_date
WHERE b.strm is not null&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i would suggest testing in a client tool (i use SQL Server a lot so i use SSMS) before trying to run it through SAS.&amp;nbsp; often the use of a client tool provides better error messaging.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;good luck&lt;/P&gt;</description>
    <pubDate>Tue, 02 Apr 2019 16:40:31 GMT</pubDate>
    <dc:creator>utrocketeng</dc:creator>
    <dc:date>2019-04-02T16:40:31Z</dc:date>
    <item>
      <title>Manipulating Data with the SQL Pass-Through Facility (delete obs)?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Manipulating-Data-with-the-SQL-Pass-Through-Facility-delete-obs/m-p/547930#M151888</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;
&lt;P&gt;I have a passthrough question on deleting a few obs directly in MS SQL?&amp;nbsp; (base SAS, &lt;SPAN style="display: inline !important; float: none; background-color: transparent; color: #333333; cursor: text; font-family: 'HelevticaNeue-light','Helvetica Neue',Helvetica,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;Windows10 SAS9.4M4 &lt;/SPAN&gt;)&lt;/P&gt;
&lt;P&gt;my code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
connect to odbc(dsn=My_dsn user=my_user password=my_pass);
select * from connection to odbc
   (
                        select strm, snap_date, emplid
						FROM [my_db].[dbo].[my_large_table] a
						where exists ( select 1 from [my_db].[dbo].[my_small_del_table] b
							where a.strm = b.strm and a.emplid = b.emplid and a.snap_date = b.snap_date)
	);

execute (&lt;U&gt;&lt;STRONG&gt;delete a.*&lt;/STRONG&gt; &lt;/U&gt;FROM [my_db].[dbo].[my_large_table] a
						where exists ( select 1 from [my_db].[dbo].[my_small_del_table] b
							where a.strm = b.strm and a.emplid = b.emplid and a.snap_date = b.snap_date)) by odbc;
disconnect from odbc;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;The first part of this code (the select) returns data just fine from my MS SQL db instance and the exact obs I want to delete.&amp;nbsp; it returns data like this to my SAS session:&lt;/P&gt;
&lt;P&gt;strm snap_date emplid&lt;BR /&gt;2177 25AUG2017:00:00:00.000 021595273&lt;BR /&gt;2177 01SEP2017:00:00:00.000 019595272&lt;BR /&gt;2177 25AUG2017:00:00:00.000 011799517&lt;BR /&gt;2177 01SEP2017:00:00:00.000 011569510&lt;BR /&gt;&lt;BR /&gt;However the second part (the execute) gives me this error:&lt;BR /&gt;ERROR: CLI execute error: [Microsoft][SQL Server Native Client 11.0][SQL Server]Incorrect syntax near '*'.&lt;BR /&gt;1561 disconnect from odbc;&lt;BR /&gt;1562 quit;&lt;BR /&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;BR /&gt;NOTE: PROCEDURE SQL used (Total process time):&lt;BR /&gt;real time 0.06 seconds&lt;BR /&gt;cpu time 0.01 seconds&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have tried these variations:&lt;BR /&gt;&lt;U&gt;&lt;FONT face="Consolas"&gt;&lt;STRONG&gt;delete a.*&lt;/STRONG&gt; &lt;/FONT&gt;&lt;/U&gt;FROM&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;FONT face="Consolas"&gt;&lt;STRONG&gt;delete &lt;/STRONG&gt;&lt;/FONT&gt;&lt;/U&gt;FROM&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;FONT face="Consolas"&gt;&lt;STRONG&gt;delete *&lt;/STRONG&gt; &lt;/FONT&gt;&lt;/U&gt;FROM&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;in place of the execute line start.&amp;nbsp; Is this possible to delete using sas pass through this way, and if yes. Can someone help me fix my code?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The larger data set is in the many millions and the small data set that needs to be deleted is just 104 obs. I really do not want to use the processing time to read to sas the full X million obs to drop the 104 obs then wright the full data set back to the db.&amp;nbsp; and I will be doing this weekly so doing it manually on the SQL server is not ideal when the rest of my SAS code runs unattended by a schedule task.&amp;nbsp; TIA&amp;nbsp; -KJ&lt;/P&gt;
&lt;P&gt;PS I have been trying to follow the examples show on page:&lt;BR /&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/spdsug/67358/HTML/default/viewer.htm#p0dc2sn22lw68xn0zu8hw6fx6kwu.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/spdsug/67358/HTML/default/viewer.htm#p0dc2sn22lw68xn0zu8hw6fx6kwu.htm&lt;/A&gt;&lt;BR /&gt;"Accessing and Manipulating Data with the SQL Pass-Through Facility"&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;If there is a better doc for sas 9.4 I will gladly use it but have not seen it so far...&lt;/P&gt;</description>
      <pubDate>Tue, 02 Apr 2019 15:32:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Manipulating-Data-with-the-SQL-Pass-Through-Facility-delete-obs/m-p/547930#M151888</guid>
      <dc:creator>kjohnsonm</dc:creator>
      <dc:date>2019-04-02T15:32:35Z</dc:date>
    </item>
    <item>
      <title>Re: Manipulating Data with the SQL Pass-Through Facility (delete obs)?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Manipulating-Data-with-the-SQL-Pass-Through-Facility-delete-obs/m-p/547954#M151901</link>
      <description>&lt;P&gt;perhaps something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;delete a.* 
FROM 
	[my_db].[dbo].[my_large_table] a
	INNER JOIN [my_db].[dbo].[my_small_del_table] b ON a.strm = b.strm and a.emplid = b.emplid and a.snap_date = b.snap_date
WHERE b.strm is not null&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i would suggest testing in a client tool (i use SQL Server a lot so i use SSMS) before trying to run it through SAS.&amp;nbsp; often the use of a client tool provides better error messaging.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;good luck&lt;/P&gt;</description>
      <pubDate>Tue, 02 Apr 2019 16:40:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Manipulating-Data-with-the-SQL-Pass-Through-Facility-delete-obs/m-p/547954#M151901</guid>
      <dc:creator>utrocketeng</dc:creator>
      <dc:date>2019-04-02T16:40:31Z</dc:date>
    </item>
    <item>
      <title>Re: Manipulating Data with the SQL Pass-Through Facility (delete obs)?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Manipulating-Data-with-the-SQL-Pass-Through-Facility-delete-obs/m-p/547970#M151903</link>
      <description>&lt;P&gt;-engineer,&lt;BR /&gt;I tried to check this code directly on SSMS, it will allow the select but blows up on the delete.&amp;nbsp; when I pre-tested it I stopped on the 'select'. Sorry my unforced error.&amp;nbsp; so I have been told this will work with oracle but not on a MS SQL server. I their for tried this coding idea.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
/* ...  I left out the user/pass lines this time etc */

/* So just upload the small data set to sql server and work them against each other locally, took about 2 min to process max */
/* Assumes you have already set small temp data set: my_small_table on to sql server */

/*	Count original data set size */
select * from connection to odbc
	(				select count(*) as all_count from my_original_table);

/*	Make temp data set without the small set of records using left join, this is a temp data set */
execute (SELECT a.*
			INTO [my_data_base].[dbo].[my_original_table_temp] 
			FROM [my_data_base].[dbo].[my_original_table] a
			left join [my_data_base].[dbo].[my_small_table] b
			on a.strm = b.strm and a.emplid = b.emplid and a.snap_date = b.snap_date
			where b.strm is null and b.emplid is null and b.snap_date is null; ) by odbc;

/*			count new total obs in temp data set */
select * from connection to odbc
	(				select count(*) as tempcount from my_original_table_temp);

/*	Delete the original data set records */
execute (DELETE FROM [my_data_base].[dbo].[my_original_table];) by odbc;

/*	Put the temp data set just made on SQL server into correct data set table */
execute (INSERT INTO [my_data_base].[dbo].[my_original_table]
SELECT * FROM [my_data_base].[dbo].[my_original_table_temp]; ) by odbc;
&lt;BR /&gt;/* PS I recommend if you need to use this over and over to clean up your temp file by dropping them here, but did not show it... */&lt;BR /&gt;
disconnect from odbc;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;it's working for me.&amp;nbsp; just more steps... but very fast compared to reading and writing millions of rows for such a small change.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Apr 2019 17:34:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Manipulating-Data-with-the-SQL-Pass-Through-Facility-delete-obs/m-p/547970#M151903</guid>
      <dc:creator>kjohnsonm</dc:creator>
      <dc:date>2019-04-02T17:34:38Z</dc:date>
    </item>
  </channel>
</rss>

