<?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: SAS to SQL conversion in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-to-SQL-conversion/m-p/417011#M280304</link>
    <description>&lt;P&gt;I am afraid not&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/179384"&gt;@RM6&lt;/a&gt;, monotonic() is a SAS function.&amp;nbsp; The OP is talking about coding SQL in another application which will a) implement ANSI SQL - this is standard SQL across all databases and what SAS also implements, and then b) the applications own function layer on that, so for example SAS provides it own functions on top of SQL, Oracle has its own library of functions in addition to ANSI SQL etc.&amp;nbsp; So functions used in one will likely not work in another unless there is a similar function built in that software.&lt;/P&gt;</description>
    <pubDate>Wed, 29 Nov 2017 11:14:44 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2017-11-29T11:14:44Z</dc:date>
    <item>
      <title>SAS to SQL conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-to-SQL-conversion/m-p/416993#M280295</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'm pretty&amp;nbsp; new SAS. I have&amp;nbsp;a piece of SAS code (pasted below) which has to be re-written in SQL. Text in bold represents the columns from the Dataset .Please let me know if you need more details.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data egs_work_suspends_2;&lt;BR /&gt;&amp;nbsp;set egs_work_suspends_1;&lt;BR /&gt;&amp;nbsp;by work_id;&lt;/P&gt;&lt;P&gt;&amp;nbsp;format saveprevstatus $100.;&lt;BR /&gt;&amp;nbsp;retain saveprevstatus;&lt;BR /&gt;&amp;nbsp;format savetmstp datetime26.6;&lt;BR /&gt;&amp;nbsp;retain savetmstp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;prevstatus = saveprevstatus;&lt;BR /&gt;&amp;nbsp;format suspendtmstp datetime26.6;&lt;BR /&gt;&amp;nbsp;suspendtmstp = savetmstp;&lt;BR /&gt;&amp;nbsp;format suspendtime 8.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;if &lt;STRONG&gt;work_status&lt;/STRONG&gt; = 'Suspended' then do;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;saveprevstatus = &lt;STRONG&gt;work_status&lt;/STRONG&gt;;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;savetmstp = &lt;STRONG&gt;work_status_tmstp&lt;/STRONG&gt;;&lt;BR /&gt;&amp;nbsp;end;&lt;BR /&gt;&amp;nbsp;if prevstatus = 'Suspended' and &lt;STRONG&gt;work_status&lt;/STRONG&gt; = 'Resumed' then do;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;paired = 1;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;suspendtime = &lt;STRONG&gt;work_status_tmstp&lt;/STRONG&gt; - suspendtmstp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;saveprevstatus = .;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;savetmstp = .;&lt;BR /&gt;&amp;nbsp;end;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Nov 2017 09:38:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-to-SQL-conversion/m-p/416993#M280295</guid>
      <dc:creator>jrajesh61</dc:creator>
      <dc:date>2017-11-29T09:38:24Z</dc:date>
    </item>
    <item>
      <title>Re: SAS to SQL conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-to-SQL-conversion/m-p/416994#M280296</link>
      <description>hi can you post some sample data&lt;BR /&gt;</description>
      <pubDate>Wed, 29 Nov 2017 09:40:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-to-SQL-conversion/m-p/416994#M280296</guid>
      <dc:creator>RM6</dc:creator>
      <dc:date>2017-11-29T09:40:07Z</dc:date>
    </item>
    <item>
      <title>Re: SAS to SQL conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-to-SQL-conversion/m-p/416995#M280297</link>
      <description>&lt;P&gt;Attached sample data here&lt;/P&gt;</description>
      <pubDate>Wed, 29 Nov 2017 09:42:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-to-SQL-conversion/m-p/416995#M280297</guid>
      <dc:creator>jrajesh61</dc:creator>
      <dc:date>2017-11-29T09:42:37Z</dc:date>
    </item>
    <item>
      <title>Re: SAS to SQL conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-to-SQL-conversion/m-p/416997#M280298</link>
      <description>Please note that in real dataset we have millions of records.</description>
      <pubDate>Wed, 29 Nov 2017 09:48:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-to-SQL-conversion/m-p/416997#M280298</guid>
      <dc:creator>jrajesh61</dc:creator>
      <dc:date>2017-11-29T09:48:23Z</dc:date>
    </item>
    <item>
      <title>Re: SAS to SQL conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-to-SQL-conversion/m-p/416999#M280299</link>
      <description>&lt;P&gt;What do you mean "it has to be converted into SQL"?&amp;nbsp; There is only one reason why you would&amp;nbsp;&lt;U&gt;&lt;STRONG&gt;need&lt;/STRONG&gt;&lt;/U&gt; SQL, and that is if you were passing the code through to a database, or coding directly on a database.&amp;nbsp; If that is the case, then you need to know what the database is, what functionality it offers etc.&amp;nbsp; The only real code here is the if statements, these can be converted to case statements.&amp;nbsp; The real problem here lies in the retain.&amp;nbsp; SQL does not have a concept of row observation like you do in SAS, so you don't retain values over.&amp;nbsp; You need to identify a specific record based on some logic, and then merge that on.&amp;nbsp; Now without any data its hard to say, but as you have some sort of sequence I assume you have a date/time sequence, so the previous state is logical defined as having max(datetime &amp;lt; current datetime), assuming your data is unique this should return the most recent record to the obs you are dealing with.&amp;nbsp; As a breif totally in the dark example:&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table WANT as 
  select  A.*,
          case when exists(select WORK_STATUS from HAVE group by ... having max(DATETIME) &amp;lt; A.DATETIME and WORK_STATUS="Suspended") then 1 else 0 as PAIRED,
   ...
  from    HAVE;
quit;&lt;/PRE&gt;
&lt;P&gt;As you can see the coding is a real pain.&amp;nbsp; If you have working SAS code, why bother going through the whole process of development testing and such like for no purpose?&lt;/P&gt;</description>
      <pubDate>Wed, 29 Nov 2017 09:54:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-to-SQL-conversion/m-p/416999#M280299</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-11-29T09:54:09Z</dc:date>
    </item>
    <item>
      <title>Re: SAS to SQL conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-to-SQL-conversion/m-p/417000#M280300</link>
      <description>&lt;P&gt;Why, isn't the current program working...?&lt;/P&gt;</description>
      <pubDate>Wed, 29 Nov 2017 09:54:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-to-SQL-conversion/m-p/417000#M280300</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2017-11-29T09:54:30Z</dc:date>
    </item>
    <item>
      <title>Re: SAS to SQL conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-to-SQL-conversion/m-p/417003#M280301</link>
      <description>&lt;P&gt;Thanks for your response. Here my requirement is to convert Reports in SAS to &lt;STRONG&gt;Microstrategy&lt;/STRONG&gt;. To do that I need to write down the freeform SQL&amp;nbsp;by looking into&amp;nbsp;SAS code. I'm stuck in this piece of code in SAS and didn't find any option to Mimic the same in&amp;nbsp;SQL .That's the&amp;nbsp; reason I reached out this forum for help in converting given piece of SAS to SQL and which would allow me to proceed further.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Nov 2017 10:07:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-to-SQL-conversion/m-p/417003#M280301</guid>
      <dc:creator>jrajesh61</dc:creator>
      <dc:date>2017-11-29T10:07:24Z</dc:date>
    </item>
    <item>
      <title>Re: SAS to SQL conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-to-SQL-conversion/m-p/417006#M280302</link>
      <description>&lt;P&gt;Well, my previous post should help, though I have never heard of Microstrategy.&amp;nbsp; The two things to look at are:&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;retain savetmstp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;- This is not in SQL (unless your app provides a function for it), so you need to code a logical sub query or join for it.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;if (xyz)&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;- These are done as case statements in SQL.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Other than that not really much I can say.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Nov 2017 10:17:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-to-SQL-conversion/m-p/417006#M280302</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-11-29T10:17:33Z</dc:date>
    </item>
    <item>
      <title>Re: SAS to SQL conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-to-SQL-conversion/m-p/417008#M280303</link>
      <description>this might be close try it&lt;BR /&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table x_1 as&lt;BR /&gt;select a.*,b.work_status as saveprevstatus,b.work_status_tmstp as savetmstp,&lt;BR /&gt;case when b.work_status = 'Suspended' and a.work_status = 'Resumed' then a.work_status_tmstp - b.work_status_tmstp end as suspendtime,&lt;BR /&gt;case when b.work_status = 'Suspended' and a.work_status = 'Resumed' then 1 end as paried&lt;BR /&gt;from (select *,MONOTONIC() as rnk from egs_work_suspends_1 ) a&lt;BR /&gt;left join (select *,MONOTONIC() as rnk from egs_work_suspends_1 ) b&lt;BR /&gt;on a.work_id=b.work_id&lt;BR /&gt;and a.rnk=b.rnk+1&lt;BR /&gt;;&lt;BR /&gt;quit;</description>
      <pubDate>Wed, 29 Nov 2017 10:39:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-to-SQL-conversion/m-p/417008#M280303</guid>
      <dc:creator>RM6</dc:creator>
      <dc:date>2017-11-29T10:39:58Z</dc:date>
    </item>
    <item>
      <title>Re: SAS to SQL conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-to-SQL-conversion/m-p/417011#M280304</link>
      <description>&lt;P&gt;I am afraid not&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/179384"&gt;@RM6&lt;/a&gt;, monotonic() is a SAS function.&amp;nbsp; The OP is talking about coding SQL in another application which will a) implement ANSI SQL - this is standard SQL across all databases and what SAS also implements, and then b) the applications own function layer on that, so for example SAS provides it own functions on top of SQL, Oracle has its own library of functions in addition to ANSI SQL etc.&amp;nbsp; So functions used in one will likely not work in another unless there is a similar function built in that software.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Nov 2017 11:14:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-to-SQL-conversion/m-p/417011#M280304</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-11-29T11:14:44Z</dc:date>
    </item>
    <item>
      <title>Re: SAS to SQL conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-to-SQL-conversion/m-p/417013#M280305</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Your correct Monotonic is not working here in SQL. Is there any alternative for&amp;nbsp; this ?&lt;/P&gt;</description>
      <pubDate>Wed, 29 Nov 2017 11:24:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-to-SQL-conversion/m-p/417013#M280305</guid>
      <dc:creator>jrajesh61</dc:creator>
      <dc:date>2017-11-29T11:24:01Z</dc:date>
    </item>
    <item>
      <title>Re: SAS to SQL conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-to-SQL-conversion/m-p/417015#M280306</link>
      <description>try using rank () over(partition by work_id) , instead of monotonic&lt;BR /&gt;</description>
      <pubDate>Wed, 29 Nov 2017 11:32:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-to-SQL-conversion/m-p/417015#M280306</guid>
      <dc:creator>RM6</dc:creator>
      <dc:date>2017-11-29T11:32:27Z</dc:date>
    </item>
    <item>
      <title>Re: SAS to SQL conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-to-SQL-conversion/m-p/417024#M280307</link>
      <description>&lt;P&gt;So have the decency to hire skilled personnel, instead of trying to get community do your work for free.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Nov 2017 12:03:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-to-SQL-conversion/m-p/417024#M280307</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2017-11-29T12:03:30Z</dc:date>
    </item>
    <item>
      <title>Re: SAS to SQL conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-to-SQL-conversion/m-p/417111#M280308</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Well, my previous post should help, though I have never heard of Microstrategy.&amp;nbsp; The two things to look at are:&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;retain savetmstp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Apparently Microstrategy is another product similar to Tableau doing "enterprise reporting".&lt;/P&gt;</description>
      <pubDate>Wed, 29 Nov 2017 15:59:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-to-SQL-conversion/m-p/417111#M280308</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-11-29T15:59:12Z</dc:date>
    </item>
    <item>
      <title>Re: SAS to SQL conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-to-SQL-conversion/m-p/417113#M280309</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/180095"&gt;@jrajesh61&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Thanks for your response. Here my requirement is to convert Reports in SAS to &lt;STRONG&gt;Microstrategy&lt;/STRONG&gt;. To do that I need to write down the freeform SQL&amp;nbsp;by looking into&amp;nbsp;SAS code. I'm stuck in this piece of code in SAS and didn't find any option to Mimic the same in&amp;nbsp;SQL .That's the&amp;nbsp; reason I reached out this forum for help in converting given piece of SAS to SQL and which would allow me to proceed further.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If your other software doesn't have the reporting tools you need then ...&lt;/P&gt;
&lt;P&gt;There is a great deal of SAS data step code that will not translate into SQL due to the nature of the differences in designed functionality. Which is one reason SAS has Proc SQL to use the features of SQL that are impossible or extremely cumbersome to implement in a data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And what will you do with SAS analytic procedure code?&lt;/P&gt;</description>
      <pubDate>Wed, 29 Nov 2017 16:02:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-to-SQL-conversion/m-p/417113#M280309</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-11-29T16:02:35Z</dc:date>
    </item>
    <item>
      <title>Re: SAS to SQL conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-to-SQL-conversion/m-p/417152#M280310</link>
      <description>&lt;P&gt;Please be aware of the following:&lt;/P&gt;
&lt;P&gt;-&amp;nbsp;&lt;STRONG&gt;Microstrategy&lt;/STRONG&gt; is a Reporting Platform that can connect to different underlying data sources (RDBMS, Hadoop, NoSQL Databaes, ...etc)&lt;/P&gt;
&lt;P&gt;- "&amp;lt;function()&amp;gt; OVER ()" are SQL Analytical functions syntax supported by selective Databases and not necessary at the same level of support!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Having said, jrajesh61 will need to investigate the ability of his SQL based data source to support these analytical functions!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just my 2 cents,&lt;/P&gt;
&lt;P&gt;Ahmed&lt;/P&gt;</description>
      <pubDate>Wed, 29 Nov 2017 17:00:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-to-SQL-conversion/m-p/417152#M280310</guid>
      <dc:creator>AhmedAl_Attar</dc:creator>
      <dc:date>2017-11-29T17:00:20Z</dc:date>
    </item>
  </channel>
</rss>

