<?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: I have some SQL code from Microsoft SQL server but not sure if you can directly run it in proc SQL? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/I-have-some-SQL-code-from-Microsoft-SQL-server-but-not-sure-if/m-p/193047#M48453</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Use real explicit pass thru that is; &lt;A href="http://support.sas.com/documentation/cdl/en/acreldb/67589/HTML/default/viewer.htm#n0pj5uu3i328pmn1fackclh2xnd9.htm" title="http://support.sas.com/documentation/cdl/en/acreldb/67589/HTML/default/viewer.htm#n0pj5uu3i328pmn1fackclh2xnd9.htm"&gt;SAS/ACCESS(R) 9.4 for Relational Databases: Reference, Sixth Edition&lt;/A&gt; mark the execute block that is the one that says SAS do not interfere that, just pass those.&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 10 Apr 2015 13:42:15 GMT</pubDate>
    <dc:creator>jakarman</dc:creator>
    <dc:date>2015-04-10T13:42:15Z</dc:date>
    <item>
      <title>I have some SQL code from Microsoft SQL server but not sure if you can directly run it in proc SQL?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/I-have-some-SQL-code-from-Microsoft-SQL-server-but-not-sure-if/m-p/193046#M48452</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-size: 18pt;"&gt;Hi everyone, &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 18pt;"&gt;I wonder if there is a way I can run SQL code directly in SAS. I know I can run something like this below:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PROC SQL;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; CONNECT TO ODBC as con&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; (DATASRC="ABCREPORTING: Prod_Report" authdomain=SQLGRP_Temp_Reader_Auth);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; CREATE TABLE ABC_Table AS &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; SELECT *&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FROM CONNECTION TO con2&lt;/P&gt;&lt;P&gt;(&lt;/P&gt;&lt;P&gt;&amp;nbsp; SELECT&lt;/P&gt;&lt;P&gt;&amp;nbsp; CASE BiasVa&lt;/P&gt;&lt;P&gt;&amp;nbsp; WHEN 1 THEN 'OO &lt;/P&gt;&lt;P&gt;&amp;nbsp; WHEN 2 THEN 'PP' &lt;/P&gt;&lt;P&gt;&amp;nbsp; END AS ABC_Type,&lt;/P&gt;&lt;P&gt;&amp;nbsp; UnitId,&lt;/P&gt;&lt;P&gt;&amp;nbsp; Stbi AS ABC_EWMA,&lt;/P&gt;&lt;P&gt;&amp;nbsp; AverageLightValue AS Avg_Actual,&lt;/P&gt;&lt;P&gt;&amp;nbsp; CONVERT(datetime, StartDateTime) AS StartDateTime,&lt;/P&gt;&lt;P&gt;&amp;nbsp; CONVERT(datetime, EndDateTime) AS EndDateTime&lt;/P&gt;&lt;P&gt;&amp;nbsp; FROM&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Derating.UnitStbiParameter&lt;/P&gt;&lt;P&gt;&amp;nbsp; WHERE UnitID IN (1,2,3,4,5,6)&lt;/P&gt;&lt;P&gt;&amp;nbsp; AND BiasCodeId IN (1,2)&lt;/P&gt;&lt;P&gt;&amp;nbsp; AND ((EndDateTime &amp;gt; StartDateTime) OR EndDateTime IS NULL )&lt;/P&gt;&lt;P&gt;&amp;nbsp; GROUP BY UnitId, ABC, AverageLightValue, StartDateTime, EndDateTime&lt;/P&gt;&lt;P&gt;&amp;nbsp; Order By StartDateTime Desc, Unitid Asc&lt;/P&gt;&lt;P&gt;);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 18pt;"&gt;However, I feel like you cannot run something with special key words in SAS like below(the declare or @sign etc may not be executed properly)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 18pt;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;DECLARE @InvestigationId VARCHAR(5) = '1166&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;IF object_id('tempdb..#ScanHistory') IS NOT NULL&lt;/P&gt;&lt;P&gt;&amp;nbsp; DROP TABLE #ScanHistory&lt;/P&gt;&lt;P&gt;SELECT ROW_NUMBER() OVER(ORDER BY IM.SubID, MSH.CreatedTime) AS RowID&lt;/P&gt;&lt;P&gt;,IM.InvestigationID&lt;/P&gt;&lt;P&gt;&amp;nbsp; ,IM.SubID&lt;/P&gt;&lt;P&gt;&amp;nbsp; ,IM.SampleDescription&lt;/P&gt;&lt;P&gt;&amp;nbsp; ,MS.Name [ModuleSubgroupName] &lt;/P&gt;&lt;P&gt;&amp;nbsp; ,CASE TE.TestFacilityID WHEN 2 THEN 'OTS' WHEN 10 THEN 'ATS' WHEN 11 THEN 'FTS' ELSE NULL END [ParentSiteID]&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp; ,RIGHT(TE.EquipmentCode,4) [ArrayID] &lt;/P&gt;&lt;P&gt;&amp;nbsp; ,CASE WHEN ID.InverterModel != 'AUT 5.8' THEN 1 ELSE&lt;/P&gt;&lt;P&gt;CASE WHEN CAST(TES.SName AS INT) &amp;gt; 10 THEN 2 ELSE 1 END &lt;/P&gt;&lt;P&gt;END [MPPT]&lt;/P&gt;&lt;P&gt;,ID.InverterModel&lt;/P&gt;&lt;P&gt;&amp;nbsp; ,TE.EquipmentCode&lt;/P&gt;&lt;P&gt;&amp;nbsp; ,TE.MaxSlots&lt;/P&gt;&lt;P&gt;&amp;nbsp; ,TES.SName&lt;/P&gt;&lt;P&gt;&amp;nbsp; ,MSH.ReasonCode&lt;/P&gt;&lt;P&gt;&amp;nbsp; INTO #ScanHistory&lt;/P&gt;&lt;P&gt;&amp;nbsp; FROM ReliabilityDB_Report.dbo.RT_InvestigationModules IM WITH (NOLOCK)&lt;/P&gt;&lt;P&gt;inner join .................................................................&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 18pt;"&gt;Just wonder if there is a way you can run SQL code directly without modifying it; Also typically when you have SQL code in hand but need to run the same thing in SAS, what is the best practice to do?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you,&lt;/P&gt;&lt;P&gt;Tao&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Apr 2015 13:29:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/I-have-some-SQL-code-from-Microsoft-SQL-server-but-not-sure-if/m-p/193046#M48452</guid>
      <dc:creator>yangtaotai</dc:creator>
      <dc:date>2015-04-10T13:29:09Z</dc:date>
    </item>
    <item>
      <title>Re: I have some SQL code from Microsoft SQL server but not sure if you can directly run it in proc SQL?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/I-have-some-SQL-code-from-Microsoft-SQL-server-but-not-sure-if/m-p/193047#M48453</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Use real explicit pass thru that is; &lt;A href="http://support.sas.com/documentation/cdl/en/acreldb/67589/HTML/default/viewer.htm#n0pj5uu3i328pmn1fackclh2xnd9.htm" title="http://support.sas.com/documentation/cdl/en/acreldb/67589/HTML/default/viewer.htm#n0pj5uu3i328pmn1fackclh2xnd9.htm"&gt;SAS/ACCESS(R) 9.4 for Relational Databases: Reference, Sixth Edition&lt;/A&gt; mark the execute block that is the one that says SAS do not interfere that, just pass those.&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Apr 2015 13:42:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/I-have-some-SQL-code-from-Microsoft-SQL-server-but-not-sure-if/m-p/193047#M48453</guid>
      <dc:creator>jakarman</dc:creator>
      <dc:date>2015-04-10T13:42:15Z</dc:date>
    </item>
    <item>
      <title>Re: I have some SQL code from Microsoft SQL server but not sure if you can directly run it in proc SQL?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/I-have-some-SQL-code-from-Microsoft-SQL-server-but-not-sure-if/m-p/193048#M48454</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That is not SQL, it is PL/SQL which is more advanced than base SQL. To my knowledge, no you cannot run PL/SQL through a proc SQL passthrough.&amp;nbsp; However why do you need the other parts, the actual operational part is the select downwards, i.e. why would you need to check if there is a temporary file on the database, this is passthrough, the results of the query get returned to SAS not put into a temporary table so you don't need that part anyway.&lt;/P&gt;&lt;P&gt;Again, same with the declare, its not needed, all you are trying to do is get the results of a query on the database passed back to SAS for further processing.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A further thing whilst looking at your code, you may also need to tweek certain parts, the INTO #Scanhistory, wouldn't make much sense in this context, as you want the results back to SAS.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Apr 2015 13:47:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/I-have-some-SQL-code-from-Microsoft-SQL-server-but-not-sure-if/m-p/193048#M48454</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-04-10T13:47:52Z</dc:date>
    </item>
    <item>
      <title>Re: I have some SQL code from Microsoft SQL server but not sure if you can directly run it in proc SQL?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/I-have-some-SQL-code-from-Microsoft-SQL-server-but-not-sure-if/m-p/193049#M48455</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE __jive_macro_name="quote" class="jive_text_macro jive_macro_quote" modifiedtitle="true"&gt;
&lt;P&gt;RW9 wrote:&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;That is not SQL, it is PL/SQL which is more advanced than base SQL. To my knowledge, no you cannot run PL/SQL through a proc SQL passthrough.&amp;nbsp; &lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I thought you could run whatever SQL the database runs. So if you're on Oracle you should be fine?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Apr 2015 14:28:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/I-have-some-SQL-code-from-Microsoft-SQL-server-but-not-sure-if/m-p/193049#M48455</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-04-10T14:28:17Z</dc:date>
    </item>
    <item>
      <title>Re: I have some SQL code from Microsoft SQL server but not sure if you can directly run it in proc SQL?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/I-have-some-SQL-code-from-Microsoft-SQL-server-but-not-sure-if/m-p/193050#M48456</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am pretty sure using the syntax select * from connection to xyz () will not be able to submit that type of code as its a query expecting a dataset back.&amp;nbsp; It may be that certain PL/SQL elements can be passed through by the use of execute() in a proc sql, per this post: &lt;A __default_attr="114173" __jive_macro_name="message" class="jive_macro jive_macro_message" href="https://communities.sas.com/"&gt;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Still begs the question why though?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Apr 2015 16:39:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/I-have-some-SQL-code-from-Microsoft-SQL-server-but-not-sure-if/m-p/193050#M48456</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-04-10T16:39:14Z</dc:date>
    </item>
  </channel>
</rss>

