<?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: PL SQL to SAS SQL in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/PL-SQL-to-SAS-SQL/m-p/535083#M146891</link>
    <description>&lt;P&gt;Just a quick note, I looked at the percentile_disc function in Oracle and it's different than most standard calculations IMO.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Look at this example:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://docs.oracle.com/cd/B19306_01/server.102/b14200/functions111.htm" target="_blank"&gt;https://docs.oracle.com/cd/B19306_01/server.102/b14200/functions111.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The median for dept_id = 30 is 2800, but really should be 2850 in most calculations. So you need to decide if that's ok with you, or if you need to match Oracles calculations.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Slight modification to&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;code, NOPRINT to prevent output to the results window and add in the WHERE statement for the filter. Again, you'll have to test this matches the Oracle functions.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc means data=work.my_table nway noprint;
where date between intnx('month', '01Jan2017'd, -1, 's') and intnx('month', '01Jan2017'd, -12, 's');

   class party_number ;

   var CREDIT_CT DEBIT_CT PCT_OUT;

   output out=work.output min=  max= p1= p5= p10= p25=
             p50= p75= p95= p99=    /autoname
               
   ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 13 Feb 2019 03:48:27 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2019-02-13T03:48:27Z</dc:date>
    <item>
      <title>PL SQL to SAS SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PL-SQL-to-SAS-SQL/m-p/535036#M146859</link>
      <description>&lt;P&gt;I'm mainly a SAS admin and developer. I have some code provided by a statistician that runs in an Oracle database.&amp;nbsp; I'm trying to figure out how to convert to SAS syntax (with PROC SQL).&amp;nbsp; My problem is that I don't understand the PERCENTILE_DISC function enough to convert to relevant SAS syntax. Anyone able to help?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; select PARTY_NUMBER, 
        Min (CREDIT_CT) as CREDIT_CT_Min,
        PERCENTILE_DISC(0.01) WITHIN GROUP (ORDER BY CREDIT_CT ASC) as CREDIT_CT_P1, 
        PERCENTILE_DISC(0.05) WITHIN GROUP (ORDER BY CREDIT_CT ASC) as CREDIT_CT_P5,
        PERCENTILE_DISC(0.10) WITHIN GROUP (ORDER BY CREDIT_CT ASC) as CREDIT_CT_P10,
        PERCENTILE_DISC(0.25) WITHIN GROUP (ORDER BY CREDIT_CT ASC) as CREDIT_CT_P25,
        PERCENTILE_DISC(0.5) WITHIN GROUP (ORDER BY CREDIT_CT ASC) as CREDIT_CT_Median,
        PERCENTILE_DISC(0.75) WITHIN GROUP (ORDER BY CREDIT_CT ASC) as CREDIT_CT_P75,
        PERCENTILE_DISC(0.95) WITHIN GROUP (ORDER BY CREDIT_CT ASC) as CREDIT_CT_P95,
        PERCENTILE_DISC(0.99) WITHIN GROUP (ORDER BY CREDIT_CT ASC) as CREDIT_CT_P99,     
        Max (CREDIT_CT) as CREDIT_CT_Max,
        Min (DEBIT_CT) as DEBIT_CT_Min,
        PERCENTILE_DISC(0.01) WITHIN GROUP (ORDER BY DEBIT_CT ASC) as DEBIT_CT_P1, 
        PERCENTILE_DISC(0.05) WITHIN GROUP (ORDER BY DEBIT_CT ASC) as DEBIT_CT_P5,
        PERCENTILE_DISC(0.10) WITHIN GROUP (ORDER BY DEBIT_CT ASC) as DEBIT_CT_P10,
        PERCENTILE_DISC(0.25) WITHIN GROUP (ORDER BY DEBIT_CT ASC) as DEBIT_CT_P25,
        PERCENTILE_DISC(0.5) WITHIN GROUP (ORDER BY DEBIT_CT ASC) as DEBIT_CT_Median,
        PERCENTILE_DISC(0.75) WITHIN GROUP (ORDER BY DEBIT_CT ASC) as DEBIT_CT_P75,
        PERCENTILE_DISC(0.95) WITHIN GROUP (ORDER BY DEBIT_CT ASC) as DEBIT_CT_P95,
        PERCENTILE_DISC(0.99) WITHIN GROUP (ORDER BY DEBIT_CT ASC) as DEBIT_CT_P99,     
        Max (DEBIT_CT) as DEBIT_CT_MAX,
        Min (PCT_OUT) as PCT_OUT_Min,
        PERCENTILE_DISC(0.01) WITHIN GROUP (ORDER BY PCT_OUT ASC) as PCT_OUT_P1, 
        PERCENTILE_DISC(0.05) WITHIN GROUP (ORDER BY PCT_OUT ASC) as PCT_OUT_P5,
        PERCENTILE_DISC(0.10) WITHIN GROUP (ORDER BY PCT_OUT ASC) as PCT_OUT_P10,
        PERCENTILE_DISC(0.25) WITHIN GROUP (ORDER BY PCT_OUT ASC) as PCT_OUT_P25,
        PERCENTILE_DISC(0.5) WITHIN GROUP (ORDER BY PCT_OUT ASC) as PCT_OUT_Median,
        PERCENTILE_DISC(0.75) WITHIN GROUP (ORDER BY PCT_OUT ASC) as PCT_OUT_P75,
        PERCENTILE_DISC(0.95) WITHIN GROUP (ORDER BY PCT_OUT ASC) as PCT_OUT_P95,
        PERCENTILE_DISC(0.99) WITHIN GROUP (ORDER BY PCT_OUT ASC) as PCT_OUT_P99,     
        Max (PCT_OUT) as PCT_OUT_Max        
from my_table
where tran_month &amp;lt;= add_months(to_date('20170901', 'YYYYMMDD'), -1)
and tran_month &amp;gt;= add_months(to_date('20170901', 'YYYYMMDD'), -12)
group by PARTY_NUMBER
order by PARTY_NUMBER;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 12 Feb 2019 22:10:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PL-SQL-to-SAS-SQL/m-p/535036#M146859</guid>
      <dc:creator>Timmy2383</dc:creator>
      <dc:date>2019-02-12T22:10:04Z</dc:date>
    </item>
    <item>
      <title>Re: PL SQL to SAS SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PL-SQL-to-SAS-SQL/m-p/535042#M146864</link>
      <description>Use PROC UNIVARIATE instead of SAS SQL, it'll be more efficient. This is just calculating summary statistics by different grouping variables and percentiles from 1 to 99th percentile which PROC UNIVARIATE or MEANS will handle.</description>
      <pubDate>Tue, 12 Feb 2019 22:20:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PL-SQL-to-SAS-SQL/m-p/535042#M146864</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-02-12T22:20:56Z</dc:date>
    </item>
    <item>
      <title>Re: PL SQL to SAS SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PL-SQL-to-SAS-SQL/m-p/535051#M146869</link>
      <description>&lt;P&gt;Thanks,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm definitely not trained in statistics or anything, so using SAS/STAT procedures is new to me.&amp;nbsp; I looked up the documentation and came up with this as a test:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc univariate data = work.my_table;
by party_number;
var CREDIT_CT DEBIT_CT PCT_OUT;
output out = work.output_table;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Am I on the right track? Can include the MIN/MAX statements from the SQL as well?&lt;/P&gt;</description>
      <pubDate>Tue, 12 Feb 2019 22:43:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PL-SQL-to-SAS-SQL/m-p/535051#M146869</guid>
      <dc:creator>Timmy2383</dc:creator>
      <dc:date>2019-02-12T22:43:36Z</dc:date>
    </item>
    <item>
      <title>Re: PL SQL to SAS SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PL-SQL-to-SAS-SQL/m-p/535059#M146874</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/29325"&gt;@Timmy2383&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm definitely not trained in statistics or anything, so using SAS/STAT procedures is new to me.&amp;nbsp; I looked up the documentation and came up with this as a test:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc univariate data = work.my_table;
by party_number;
var CREDIT_CT DEBIT_CT PCT_OUT;
output out = work.output_table;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Am I on the right track? Can include the MIN/MAX statements from the SQL as well?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I might suggest :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc summary data=work.my_table nway;
   class party_number;
   var CREDIT_CT DEBIT_CT PCT_OUT;
   output out=work.output min=  max= p1= p5= p10= p25=
             p50= p75= p95= p99=    /autoname
               
   ;
run;&lt;/PRE&gt;
&lt;P&gt;The CLASS statement works similar to BY with a big difference for programming: it does not require data to be sorted as BY group processing does. If the main purpose is to create an output data set then SUMMARY does that without all of the tables that Univariate or Means would (though you can suppress them). The / autoname option can save a lot of code naming variables as this appends the statistic to the VAR variables names.&lt;/P&gt;
&lt;P&gt;Another advantage with Summary/means and class statements is that without the option NWAY then you get additional summaries for combinations of the class variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;P50 can be called median if your prefer and P25/P75 can be Q1 and Q3.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Feb 2019 23:18:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PL-SQL-to-SAS-SQL/m-p/535059#M146874</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-02-12T23:18:26Z</dc:date>
    </item>
    <item>
      <title>Re: PL SQL to SAS SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PL-SQL-to-SAS-SQL/m-p/535067#M146881</link>
      <description>&lt;P&gt;&lt;EM&gt;The CLASS statement works similar to BY with a big difference for programming: it does not require data to be sorted&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;Another difference is that CLASS is usually (counter-intuitively) faster than BY, probably to do with the (suboptimal?) supplementary order-checking logic that SAS uses when a BY statement is present.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Feb 2019 00:35:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PL-SQL-to-SAS-SQL/m-p/535067#M146881</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-02-13T00:35:32Z</dc:date>
    </item>
    <item>
      <title>Re: PL SQL to SAS SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PL-SQL-to-SAS-SQL/m-p/535083#M146891</link>
      <description>&lt;P&gt;Just a quick note, I looked at the percentile_disc function in Oracle and it's different than most standard calculations IMO.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Look at this example:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://docs.oracle.com/cd/B19306_01/server.102/b14200/functions111.htm" target="_blank"&gt;https://docs.oracle.com/cd/B19306_01/server.102/b14200/functions111.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The median for dept_id = 30 is 2800, but really should be 2850 in most calculations. So you need to decide if that's ok with you, or if you need to match Oracles calculations.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Slight modification to&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;code, NOPRINT to prevent output to the results window and add in the WHERE statement for the filter. Again, you'll have to test this matches the Oracle functions.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc means data=work.my_table nway noprint;
where date between intnx('month', '01Jan2017'd, -1, 's') and intnx('month', '01Jan2017'd, -12, 's');

   class party_number ;

   var CREDIT_CT DEBIT_CT PCT_OUT;

   output out=work.output min=  max= p1= p5= p10= p25=
             p50= p75= p95= p99=    /autoname
               
   ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Feb 2019 03:48:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PL-SQL-to-SAS-SQL/m-p/535083#M146891</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-02-13T03:48:27Z</dc:date>
    </item>
    <item>
      <title>Re: PL SQL to SAS SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PL-SQL-to-SAS-SQL/m-p/535085#M146893</link>
      <description>&lt;P&gt;Thank you all!&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This gives me a lot to go on.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Feb 2019 03:52:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PL-SQL-to-SAS-SQL/m-p/535085#M146893</guid>
      <dc:creator>Timmy2383</dc:creator>
      <dc:date>2019-02-13T03:52:54Z</dc:date>
    </item>
  </channel>
</rss>

