<?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: PostgreSQL code translate into FEDSQL or SAS in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/PostgreSQL-code-translate-into-FEDSQL-or-SAS/m-p/405723#M12381</link>
    <description>&lt;P&gt;This might not be straight forward answer but a reference to solve the problem. In your query you are using olap functions for example&lt;/P&gt;
&lt;P&gt;&amp;nbsp;LAG(Extubated,1)&lt;BR /&gt;OVER&lt;BR /&gt;(&lt;BR /&gt;partition by icustay_id, case when MechVent=1 or Extubated=1 then 1 else 0 end&lt;BR /&gt;order by charttime&lt;BR /&gt;) as ExtubatedLag&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;below is the paper which tell how to emulate olap functions in SAS. Even though this&amp;nbsp;paper for Teradata, it is very valid for PostgreSQL query you have pasted&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/resources/papers/proceedings11/019-2011.pdf" target="_blank"&gt;http://support.sas.com/resources/papers/proceedings11/019-2011.pdf&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 19 Oct 2017 20:10:45 GMT</pubDate>
    <dc:creator>kiranv_</dc:creator>
    <dc:date>2017-10-19T20:10:45Z</dc:date>
    <item>
      <title>PostgreSQL code translate into FEDSQL or SAS</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/PostgreSQL-code-translate-into-FEDSQL-or-SAS/m-p/405679#M12380</link>
      <description>&lt;P&gt;Hi. I would like to translate postgreSQL below code into SAS or FEDSQL. Can anyone help? Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;select&lt;BR /&gt;icustay_id&lt;BR /&gt;, charttime_lag&lt;BR /&gt;, charttime&lt;BR /&gt;, MechVent&lt;BR /&gt;, OxygenTherapy&lt;BR /&gt;, Extubated&lt;BR /&gt;, SelfExtubated&lt;/P&gt;&lt;P&gt;/* -- if this is a mechanical ventilation event, we calculate the time since the last event*/&lt;BR /&gt;, case&lt;BR /&gt;/* -- if the current observation indicates mechanical ventilation is present*/&lt;BR /&gt;/* -- calculate the time since the last vent event*/&lt;BR /&gt;when MechVent=1 then&lt;BR /&gt;CHARTTIME - charttime_lag&lt;BR /&gt;else null&lt;BR /&gt;end as ventduration&lt;/P&gt;&lt;P&gt;, LAG(Extubated,1)&lt;BR /&gt;OVER&lt;BR /&gt;(&lt;BR /&gt;partition by icustay_id, case when MechVent=1 or Extubated=1 then 1 else 0 end&lt;BR /&gt;order by charttime&lt;BR /&gt;) as ExtubatedLag&lt;/P&gt;&lt;P&gt;/* -- now we determine if the current mech vent event is a "new", i.e. they've just been intubated*/&lt;BR /&gt;, case&lt;BR /&gt;/* -- if there is an extubation flag, we mark any subsequent ventilation as a new ventilation event*/&lt;BR /&gt;/* --when Extubated = 1 then 0 -- extubation is *not* a new ventilation event, the *subsequent* row is*/&lt;BR /&gt;when&lt;BR /&gt;LAG(Extubated,1)&lt;BR /&gt;OVER&lt;BR /&gt;(&lt;BR /&gt;partition by icustay_id, case when MechVent=1 or Extubated=1 then 1 else 0 end&lt;BR /&gt;order by charttime&lt;BR /&gt;)&lt;BR /&gt;= 1 then 1&lt;BR /&gt;/* -- if patient has initiated oxygen therapy, and is not currently vented, start a newvent*/&lt;BR /&gt;when MechVent = 0 and OxygenTherapy = 1 then 1&lt;BR /&gt;/* -- if there is less than 8 hours between vent settings, we do not treat this as a new ventilation event*/&lt;BR /&gt;when (CHARTTIME - charttime_lag) &amp;gt; 8&lt;BR /&gt;then 1&lt;BR /&gt;else 0&lt;BR /&gt;end as newvent&lt;BR /&gt;/* -- use the staging table with only vent settings from chart events*/&lt;BR /&gt;FROM vd0 ventsettings&lt;BR /&gt;;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Oct 2017 18:35:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/PostgreSQL-code-translate-into-FEDSQL-or-SAS/m-p/405679#M12380</guid>
      <dc:creator>Zula</dc:creator>
      <dc:date>2017-10-19T18:35:15Z</dc:date>
    </item>
    <item>
      <title>Re: PostgreSQL code translate into FEDSQL or SAS</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/PostgreSQL-code-translate-into-FEDSQL-or-SAS/m-p/405723#M12381</link>
      <description>&lt;P&gt;This might not be straight forward answer but a reference to solve the problem. In your query you are using olap functions for example&lt;/P&gt;
&lt;P&gt;&amp;nbsp;LAG(Extubated,1)&lt;BR /&gt;OVER&lt;BR /&gt;(&lt;BR /&gt;partition by icustay_id, case when MechVent=1 or Extubated=1 then 1 else 0 end&lt;BR /&gt;order by charttime&lt;BR /&gt;) as ExtubatedLag&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;below is the paper which tell how to emulate olap functions in SAS. Even though this&amp;nbsp;paper for Teradata, it is very valid for PostgreSQL query you have pasted&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/resources/papers/proceedings11/019-2011.pdf" target="_blank"&gt;http://support.sas.com/resources/papers/proceedings11/019-2011.pdf&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Oct 2017 20:10:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/PostgreSQL-code-translate-into-FEDSQL-or-SAS/m-p/405723#M12381</guid>
      <dc:creator>kiranv_</dc:creator>
      <dc:date>2017-10-19T20:10:45Z</dc:date>
    </item>
  </channel>
</rss>

