<?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: Help in Proc sql code in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Help-in-Proc-sql-code/m-p/460341#M117000</link>
    <description>&lt;P&gt;Your code was close. Here are a couple of needed changes:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
  CREATE TABLE TWO AS
    SELECT id,trt,
           input(date,is8601dt.) as exstdt format datetime18.,
           ((max(datepart(calculated exstdt))-
             min(datepart(calculated exstdt)))+1) /7 as aval,
           count(id) as ava
      from one
        group by id,trt         
  ;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 07 May 2018 01:19:46 GMT</pubDate>
    <dc:creator>art297</dc:creator>
    <dc:date>2018-05-07T01:19:46Z</dc:date>
    <item>
      <title>Help in Proc sql code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-in-Proc-sql-code/m-p/460336#M116998</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
input id trt$ date $18.;
DATALINES;
1 A 2014-04-26T13:10
1 A 2014-05-17T11:30
1 A 2014-06-07T11:45
1 A 2014-06-28T13:30
1 B 2014-04-26T13:10
1 B 2014-05-17T11:30
1 B 2014-06-07T11:45
1 B 2014-06-28T13:30
2 A 2014-04-26T13:10
2 A 2014-05-17T11:30
2 A 2014-06-07T11:45
2 A 2014-06-28T13:30
2 B 2014-04-26T13:10
2 B 2014-05-17T11:30
2 B 2014-06-07T11:45
2 B 2014-06-28T13:30
;
PROC SQL;
CREATE TABLE TWO AS
SELECT id,trt,input(date,is8601dt.) as exstdt format datetime18.,((max(datepart(exstdt))-min(datepart(exstdt)))+1) /7 as aval,count(id) as ava,
group by id,trt
                
from one;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Dear,&lt;/P&gt;
&lt;P&gt;I am trying to do some calculations in my data. I think I can do by datasteps, but I want to try proc sql. Please help. Thank you&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;rules;&lt;/P&gt;
&lt;P&gt;Calculate by id,trt&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;param= 'numberofrecords"&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; count number of obs by id and trt&lt;BR /&gt;param="duration in weeks"&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;last date-first date+1 converted to weeks&amp;nbsp; &amp;nbsp;by id,trt&lt;BR /&gt;param="compliance"&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;numberofrecords/{round(durationinweeks/3)+1}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I did not populate the aval values for param="duration in weeks" and "compliance" as I do not know what values I get from the code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;output needed:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;id trt param aval&lt;BR /&gt;1 A numberofrecords 4&lt;BR /&gt;1 A durartioninweeks &lt;BR /&gt;1 A compliance&lt;BR /&gt;1 B numberofrecords 4&lt;BR /&gt;1 B durartioninweeks &lt;BR /&gt;1 B compliance&lt;BR /&gt;2 A numberofrecords 4&lt;BR /&gt;2 A durartioninweeks &lt;BR /&gt;2 A compliance&lt;BR /&gt;2 B numberofrecords 4&lt;BR /&gt;2 B durartioninweeks &lt;BR /&gt;2 B compliance&lt;/P&gt;</description>
      <pubDate>Sun, 06 May 2018 23:54:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-in-Proc-sql-code/m-p/460336#M116998</guid>
      <dc:creator>knveraraju91</dc:creator>
      <dc:date>2018-05-06T23:54:33Z</dc:date>
    </item>
    <item>
      <title>Re: Help in Proc sql code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-in-Proc-sql-code/m-p/460341#M117000</link>
      <description>&lt;P&gt;Your code was close. Here are a couple of needed changes:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
  CREATE TABLE TWO AS
    SELECT id,trt,
           input(date,is8601dt.) as exstdt format datetime18.,
           ((max(datepart(calculated exstdt))-
             min(datepart(calculated exstdt)))+1) /7 as aval,
           count(id) as ava
      from one
        group by id,trt         
  ;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 May 2018 01:19:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-in-Proc-sql-code/m-p/460341#M117000</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2018-05-07T01:19:46Z</dc:date>
    </item>
    <item>
      <title>Re: Help in Proc sql code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-in-Proc-sql-code/m-p/460343#M117002</link>
      <description>&lt;P&gt;Thank you.&lt;/P&gt;
&lt;P&gt;How to write code for&amp;nbsp; param values for each calculated aval values.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 May 2018 02:04:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-in-Proc-sql-code/m-p/460343#M117002</guid>
      <dc:creator>knveraraju91</dc:creator>
      <dc:date>2018-05-07T02:04:54Z</dc:date>
    </item>
    <item>
      <title>Re: Help in Proc sql code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-in-Proc-sql-code/m-p/460346#M117003</link>
      <description>&lt;P&gt;You'll have to check the following code to insure that the calculations are those which you actually need:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
  CREATE TABLE TWO AS
    SELECT id,trt,
           input(date,is8601dt.) as exstdt format datetime18.,
           ((max(datepart(calculated exstdt))-
             min(datepart(calculated exstdt)))+1) /7 as aval,
           count(id) as ava,
           intck('week',min(datepart(calculated exstdt)),
              max(datepart(calculated exstdt)),'c') as duration,
           calculated ava/(round(calculated duration/3)+1) as compliance
      from one
        group by id,trt         
  ;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 May 2018 03:22:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-in-Proc-sql-code/m-p/460346#M117003</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2018-05-07T03:22:41Z</dc:date>
    </item>
  </channel>
</rss>

