<?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: converting sas code to sql in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/converting-sas-code-to-sql/m-p/186614#M47401</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Agree with Arthur, being asked to rewritte this is very odd. SQL may not be faster at all.&lt;/P&gt;&lt;P&gt;You need to optimise in other ways (try compressing tables for example).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 27 Feb 2015 21:14:39 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2015-02-27T21:14:39Z</dc:date>
    <item>
      <title>converting sas code to sql</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/converting-sas-code-to-sql/m-p/186611#M47398</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a dataset with about 6 million observations and this sas data step is insufficient so I was asked to run it as an sql query.&amp;nbsp; I am not familiar how to phrase if then statements in sql within a select statement as well as format variables.&amp;nbsp; The original code looks like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data convert_code;&lt;/P&gt;&lt;P&gt;format date1 date 2 mmddyy8. code $4.;&lt;/P&gt;&lt;P&gt;set userid.code; (this table is pulled from oracle)&lt;/P&gt;&lt;P&gt;if ID='X' then P='A'; else P='B';&lt;/P&gt;&lt;P&gt;If CAT in ('1','2','3') then CAT_group='ONE'; else CAT_GROUP='TWO';&lt;/P&gt;&lt;P&gt;if CAT_2 &amp;gt; '0' and CAT_2A &amp;gt;='1' then d=1; else d=0;&lt;/P&gt;&lt;P&gt;date1=datepart(date1);&lt;/P&gt;&lt;P&gt;date2=datepart(date2);&lt;/P&gt;&lt;P&gt;if code='3' and type_code in ('A','B','C') THEN DO;&lt;/P&gt;&lt;P&gt;if P_CODE in ('1','2','3') then P='1';&lt;/P&gt;&lt;P&gt;if P_CODE in ('4','5','6') then P='2';&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;if code='4' and e_code in ('A') then DO;&lt;/P&gt;&lt;P&gt;if B_CODE in ('11','12','13') then P='3';&lt;/P&gt;&lt;P&gt;if B_CODE in ('14','15','16') then P='4';&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 27 Feb 2015 19:27:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/converting-sas-code-to-sql/m-p/186611#M47398</guid>
      <dc:creator>pinkyc</dc:creator>
      <dc:date>2015-02-27T19:27:45Z</dc:date>
    </item>
    <item>
      <title>Re: converting sas code to sql</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/converting-sas-code-to-sql/m-p/186612#M47399</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;if ID='X' then P='A'; else P='B';&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;Becomes&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;Case when ID='X' then 'A'&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;else 'B' end as P format=$1.,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;The rest is similar though you may need to nest case statements and format where appropriate.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 27 Feb 2015 20:29:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/converting-sas-code-to-sql/m-p/186612#M47399</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-02-27T20:29:56Z</dc:date>
    </item>
    <item>
      <title>Re: converting sas code to sql</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/converting-sas-code-to-sql/m-p/186613#M47400</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Your code only takes about 3 seconds to run on an old machine. Why is it being considered insufficient?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Proc SQL may not do it any quicker.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 27 Feb 2015 21:03:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/converting-sas-code-to-sql/m-p/186613#M47400</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2015-02-27T21:03:00Z</dc:date>
    </item>
    <item>
      <title>Re: converting sas code to sql</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/converting-sas-code-to-sql/m-p/186614#M47401</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Agree with Arthur, being asked to rewritte this is very odd. SQL may not be faster at all.&lt;/P&gt;&lt;P&gt;You need to optimise in other ways (try compressing tables for example).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 27 Feb 2015 21:14:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/converting-sas-code-to-sql/m-p/186614#M47401</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2015-02-27T21:14:39Z</dc:date>
    </item>
    <item>
      <title>Re: converting sas code to sql</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/converting-sas-code-to-sql/m-p/186615#M47402</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Does userid.code point to an actual Oracle table? If it does then SAS is translating your code into SQL anyway behind the scenes.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If userid.code is a SAS table extracted from Oracle first then you could combine the extraction and your code into one step and that would definitely be quicker. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 28 Feb 2015 01:21:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/converting-sas-code-to-sql/m-p/186615#M47402</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2015-02-28T01:21:46Z</dc:date>
    </item>
    <item>
      <title>Re: converting sas code to sql</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/converting-sas-code-to-sql/m-p/186616#M47403</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So 99% of the time that data step is taking is pulling the data from Oracle to SAS.&amp;nbsp; Re-coding the IF/THEN to CASE statements will not help with that.&lt;/P&gt;&lt;P&gt;The best thing you can do is to cut down on the amount of data you need to pull from Oracle to SAS.&lt;/P&gt;&lt;P&gt;Perhaps you could add a KEEP data set option to only move the variables you need?&lt;/P&gt;&lt;P&gt;Perhaps you could add a WHERE statement to only move the observations you need?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 28 Feb 2015 01:51:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/converting-sas-code-to-sql/m-p/186616#M47403</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2015-02-28T01:51:19Z</dc:date>
    </item>
    <item>
      <title>Re: converting sas code to sql</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/converting-sas-code-to-sql/m-p/186617#M47404</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;A mentioning Oracle and a SAS datastep. As Tom already stated you problem is not the datastep/SQL. Normally complex function with a datastep are faster and can doe more as SQL.&lt;/P&gt;&lt;P&gt;Your real problem is the data movement from oracle to SAS as the data is saved in the saswork the destination is unclear. &lt;BR /&gt;When the destination is SAS the goal is to minimize the needed data&amp;nbsp; (keep and where)&lt;BR /&gt;When the destination is back to Oracle the whole processing could be done in Oracle using implicit or explicit SQL.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;With Oracle there is no support for in-database processing and publishing SAS formats. &lt;A href="http://support.sas.com/documentation/cdl/en/indbug/67366/HTML/default/viewer.htm#p0ytpkucopxnazn1sfyvdurldu0y.htm" title="http://support.sas.com/documentation/cdl/en/indbug/67366/HTML/default/viewer.htm#p0ytpkucopxnazn1sfyvdurldu0y.htm"&gt;SAS(R) 9.4 In-Database Products: User's Guide, Fourth Edition&lt;/A&gt;&amp;nbsp;&amp;nbsp; The approach for using formats with in-database is a nogo.&lt;/P&gt;&lt;P&gt;The only SAS fucntions being supported are of the Oracle &lt;A href="http://support.sas.com/documentation/cdl/en/acreldb/67589/HTML/default/viewer.htm#p0f64yzzxbsg8un1uwgstc6fivjd.htm" title="http://support.sas.com/documentation/cdl/en/acreldb/67589/HTML/default/viewer.htm#p0f64yzzxbsg8un1uwgstc6fivjd.htm"&gt;SAS/ACCESS(R) 9.4 for Relational Databases: Reference, Sixth Edition&lt;/A&gt;&amp;nbsp; &lt;/P&gt;&lt;P&gt;The datepart (date1/date2) to be eliminiated (oracle/sas datetime difference) and only focus on that new variable code.&amp;nbsp; &lt;BR /&gt;The case and in of&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;A href="http://support.sas.com/documentation/cdl/en/sqlproc/65065/HTML/default/viewer.htm#n0a85s0ijz65irn1h3jtariooea5.htm" title="http://support.sas.com/documentation/cdl/en/sqlproc/65065/HTML/default/viewer.htm#n0a85s0ijz65irn1h3jtariooea5.htm"&gt;SAS(R) 9.4 SQL Procedure User's Guide&lt;/A&gt; should be able to work well for a implicit one (most easy to code). &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 28 Feb 2015 11:47:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/converting-sas-code-to-sql/m-p/186617#M47404</guid>
      <dc:creator>jakarman</dc:creator>
      <dc:date>2015-02-28T11:47:48Z</dc:date>
    </item>
    <item>
      <title>Re: converting sas code to sql</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/converting-sas-code-to-sql/m-p/186618#M47405</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi all who answered,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is pinkyc, I no longer have access to the account due to my college discontinuing my email and can't reset my password so I apologize that I cannot tick helpful answers for this thread.&amp;nbsp; I think the issue as Tom correctly pointed out is that the table I was pulling from (userid.) didn't have 6 million observations, more like 60 million which was caused by a query that wasn't specific enough.&amp;nbsp; So I fixed that to actually 6 million and it ran fine.&amp;nbsp; Thanks everyone else too! &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Mar 2015 16:14:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/converting-sas-code-to-sql/m-p/186618#M47405</guid>
      <dc:creator>appleorange</dc:creator>
      <dc:date>2015-03-02T16:14:54Z</dc:date>
    </item>
  </channel>
</rss>

