<?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: proc sql; in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql/m-p/34291#M8358</link>
    <description>Hello SSS,&lt;BR /&gt;
&lt;BR /&gt;
This is a solution:&lt;BR /&gt;
[pre]&lt;BR /&gt;
proc SQL;&lt;BR /&gt;
  create table t as&lt;BR /&gt;
  select id, min(date) as min, max(date) as max &lt;BR /&gt;
  from i&lt;BR /&gt;
  group by ID  &lt;BR /&gt;
;quit;&lt;BR /&gt;
proc SQL;&lt;BR /&gt;
  create table r as&lt;BR /&gt;
  select a.id, a.date,&lt;BR /&gt;
  case &lt;BR /&gt;
    when date=min or max-min=0 then .&lt;BR /&gt;
    else max-min&lt;BR /&gt;
  end as TBF&lt;BR /&gt;
  from i as a left join t as b&lt;BR /&gt;
  on a.ID=b.ID&lt;BR /&gt;
  order by ID, date &lt;BR /&gt;
;quit; &lt;BR /&gt;
[/pre]&lt;BR /&gt;
Sincerely,&lt;BR /&gt;
SPR</description>
    <pubDate>Tue, 22 Mar 2011 13:22:51 GMT</pubDate>
    <dc:creator>SPR</dc:creator>
    <dc:date>2011-03-22T13:22:51Z</dc:date>
    <item>
      <title>proc sql;</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql/m-p/34286#M8353</link>
      <description>HI All,&lt;BR /&gt;
I want to find TBF(Time Between Failure) with respect to id. Sampe data goes here...................&lt;BR /&gt;
&lt;BR /&gt;
data new;&lt;BR /&gt;
input id$ date:date9.;&lt;BR /&gt;
FORMAT DATE DATE9.;&lt;BR /&gt;
datalines;&lt;BR /&gt;
a 15aug2007&lt;BR /&gt;
a 21apr2009&lt;BR /&gt;
b 05may2009&lt;BR /&gt;
c 15may2009&lt;BR /&gt;
d 01feb2010&lt;BR /&gt;
d 01mar2010&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
output&lt;BR /&gt;
====================&lt;BR /&gt;
ID  date               TBF&lt;BR /&gt;
a 15aug2007      .&lt;BR /&gt;
a 21apr2009    615&lt;BR /&gt;
b 05may2009     .&lt;BR /&gt;
c 15may2009    .&lt;BR /&gt;
d 01feb2010      .&lt;BR /&gt;
d 01mar2010    28&lt;BR /&gt;
&lt;BR /&gt;
I tried with oracle code it is working fine .code goes here&lt;BR /&gt;
&lt;BR /&gt;
select *, TRUNC(TO_CHAR(date- lag(date,1) OVER (PARTITION BY assetnum ORDER BY faildate)),2) AS TBF_Days from table1 &lt;BR /&gt;
by id;&lt;BR /&gt;
&lt;BR /&gt;
but when i am tring to execute same code in proc sql then i m getting error msg like&lt;BR /&gt;
PARTITION BY not define lag cant be used in proc sql . I think there are restriction are there .&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
I want to get the put using proc sql.&lt;BR /&gt;
&lt;BR /&gt;
I tried with Lag and dif function in Data Step but not getting the output.&lt;BR /&gt;
&lt;BR /&gt;
please help me out.</description>
      <pubDate>Mon, 21 Mar 2011 14:15:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql/m-p/34286#M8353</guid>
      <dc:creator>sss</dc:creator>
      <dc:date>2011-03-21T14:15:13Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql;</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql/m-p/34287#M8354</link>
      <description>Hello SSS,&lt;BR /&gt;
&lt;BR /&gt;
This is a solution:&lt;BR /&gt;
[pre]&lt;BR /&gt;
data i;&lt;BR /&gt;
input id$ date:date9.;&lt;BR /&gt;
FORMAT DATE DATE9.;&lt;BR /&gt;
datalines;&lt;BR /&gt;
a 15aug2007&lt;BR /&gt;
a 21apr2009&lt;BR /&gt;
b 05may2009&lt;BR /&gt;
c 15may2009&lt;BR /&gt;
d 01feb2010&lt;BR /&gt;
d 01mar2010&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
proc sort data=i;&lt;BR /&gt;
  by id date;&lt;BR /&gt;
run;&lt;BR /&gt;
data r;&lt;BR /&gt;
  retain fd;&lt;BR /&gt;
  set i;&lt;BR /&gt;
  if FIRST.ID then fd=date; &lt;BR /&gt;
  if LAST.ID then TBF=date-fd;  &lt;BR /&gt;
  if FIRST.ID and LAST.ID then TBF=.;&lt;BR /&gt;
  by ID;&lt;BR /&gt;
  drop fd;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
Sincerely,&lt;BR /&gt;
SPR</description>
      <pubDate>Mon, 21 Mar 2011 15:05:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql/m-p/34287#M8354</guid>
      <dc:creator>SPR</dc:creator>
      <dc:date>2011-03-21T15:05:50Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql;</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql/m-p/34288#M8355</link>
      <description>Hey buddy&lt;BR /&gt;
thnxs a lot it works</description>
      <pubDate>Mon, 21 Mar 2011 15:13:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql/m-p/34288#M8355</guid>
      <dc:creator>sss</dc:creator>
      <dc:date>2011-03-21T15:13:59Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql;</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql/m-p/34289#M8356</link>
      <description>I am a bit surprised why do you need all those TBF=. ? May be better exclude them?&lt;BR /&gt;
 &lt;BR /&gt;
SPR</description>
      <pubDate>Mon, 21 Mar 2011 15:28:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql/m-p/34289#M8356</guid>
      <dc:creator>SPR</dc:creator>
      <dc:date>2011-03-21T15:28:08Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql;</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql/m-p/34290#M8357</link>
      <description>HI SPR,&lt;BR /&gt;
&lt;BR /&gt;
I am calculating TBF for asset.&lt;BR /&gt;
how frequently it has failed and and the time.&lt;BR /&gt;
&lt;BR /&gt;
 u can see for Asset A: it has failed for 2 time . so, i wnt 2 calculate the TBF for the asset&lt;BR /&gt;
                           Asset B: its only 1 time and so on&lt;BR /&gt;
&lt;BR /&gt;
Hey can we do same task using proc sql ? if possble plz suggest me &lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
thnx &lt;BR /&gt;
shivkumar</description>
      <pubDate>Tue, 22 Mar 2011 09:45:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql/m-p/34290#M8357</guid>
      <dc:creator>sss</dc:creator>
      <dc:date>2011-03-22T09:45:42Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql;</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql/m-p/34291#M8358</link>
      <description>Hello SSS,&lt;BR /&gt;
&lt;BR /&gt;
This is a solution:&lt;BR /&gt;
[pre]&lt;BR /&gt;
proc SQL;&lt;BR /&gt;
  create table t as&lt;BR /&gt;
  select id, min(date) as min, max(date) as max &lt;BR /&gt;
  from i&lt;BR /&gt;
  group by ID  &lt;BR /&gt;
;quit;&lt;BR /&gt;
proc SQL;&lt;BR /&gt;
  create table r as&lt;BR /&gt;
  select a.id, a.date,&lt;BR /&gt;
  case &lt;BR /&gt;
    when date=min or max-min=0 then .&lt;BR /&gt;
    else max-min&lt;BR /&gt;
  end as TBF&lt;BR /&gt;
  from i as a left join t as b&lt;BR /&gt;
  on a.ID=b.ID&lt;BR /&gt;
  order by ID, date &lt;BR /&gt;
;quit; &lt;BR /&gt;
[/pre]&lt;BR /&gt;
Sincerely,&lt;BR /&gt;
SPR</description>
      <pubDate>Tue, 22 Mar 2011 13:22:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql/m-p/34291#M8358</guid>
      <dc:creator>SPR</dc:creator>
      <dc:date>2011-03-22T13:22:51Z</dc:date>
    </item>
  </channel>
</rss>

