<?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 Less Data Step &amp;amp; less proc sql posibilites to get same result in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Less-Data-Step-amp-less-proc-sql-posibilites-to-get-same-result/m-p/225692#M40534</link>
    <description>&lt;P&gt;I got the result what i want at the following steps but i wonder to have better performance, are there any posibilities to get same result with less data steps or proc sql steps.&lt;/P&gt;&lt;P&gt;Data will work when you run the EG.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data default;&lt;BR /&gt;length default 8. Data 8. ;&lt;BR /&gt;infile datalines missover;&lt;BR /&gt;input Default Data ;&lt;BR /&gt;datalines;&lt;BR /&gt;1 0.0625&lt;BR /&gt;0 0.125&lt;BR /&gt;1 0.1875&lt;BR /&gt;0 0.25&lt;BR /&gt;1 0.3125&lt;BR /&gt;0 0.375&lt;BR /&gt;1 0.4375&lt;BR /&gt;0 0.5&lt;BR /&gt;1 0.5625&lt;BR /&gt;0 0.625&lt;BR /&gt;0 0.6875&lt;BR /&gt;1 0.75&lt;BR /&gt;1 0.8125&lt;BR /&gt;0 0.875&lt;BR /&gt;1 0.9375&lt;BR /&gt;;&lt;BR /&gt;proc sort data=work.default;&lt;BR /&gt;by descending Data;&lt;BR /&gt;run;&lt;BR /&gt;data work.cumulative;&lt;BR /&gt;set work.default;&lt;BR /&gt;NonDefault=1-Default;&lt;BR /&gt;by data notsorted;&lt;BR /&gt;if first.id then defaultRate=0;&lt;BR /&gt;defaultRate+default;&lt;BR /&gt;if first.id then NondefaultRate=0;&lt;BR /&gt;NondefaultRate+Nondefault;&lt;BR /&gt;run;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table work.cumulative2 as&lt;BR /&gt;select default,data,NonDefault,defaultRate,NondefaultRate,sum(default) as TotalDefault,sum(NonDefault) as TotalNonDefault&lt;BR /&gt;from work.cumulative;&lt;BR /&gt;quit;&lt;BR /&gt;data work.cumulativeResult;&lt;BR /&gt;set work.cumulative2 END=lastN;&lt;BR /&gt;ResultD=defaultRate/TotalDefault;&lt;BR /&gt;ResultND=NondefaultRate/TotalNonDefault;&lt;BR /&gt;Retain Sonuc 0;&lt;BR /&gt;/*IF _n_=1 then Area=(ResultND/2)*ResultD;&lt;BR /&gt;ELSE*/Area=(ResultND+Lag(ResultND))/2*(ResultD-Lag(ResultD));&lt;BR /&gt;IF missing(Area)=1 then Area2=0;&lt;BR /&gt;Else Area2=Area;&lt;BR /&gt;Sonuc=Sonuc+Area2;&lt;BR /&gt;run;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table cumulativeResultMax as&lt;BR /&gt;select max(Sonuc) as MaxSonuc&lt;BR /&gt;from cumulativeResult;&lt;BR /&gt;quit;&lt;BR /&gt;data PowerStat;&lt;BR /&gt;set work.cumulativeresultmax;&lt;BR /&gt;PowerStat=(MaxSonuc-0.5)*2;&lt;BR /&gt;ABSResult=ABS(PowerStat);&lt;BR /&gt;run;&lt;/P&gt;</description>
    <pubDate>Tue, 15 Sep 2015 19:47:12 GMT</pubDate>
    <dc:creator>turcay</dc:creator>
    <dc:date>2015-09-15T19:47:12Z</dc:date>
    <item>
      <title>Less Data Step &amp; less proc sql posibilites to get same result</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Less-Data-Step-amp-less-proc-sql-posibilites-to-get-same-result/m-p/225692#M40534</link>
      <description>&lt;P&gt;I got the result what i want at the following steps but i wonder to have better performance, are there any posibilities to get same result with less data steps or proc sql steps.&lt;/P&gt;&lt;P&gt;Data will work when you run the EG.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data default;&lt;BR /&gt;length default 8. Data 8. ;&lt;BR /&gt;infile datalines missover;&lt;BR /&gt;input Default Data ;&lt;BR /&gt;datalines;&lt;BR /&gt;1 0.0625&lt;BR /&gt;0 0.125&lt;BR /&gt;1 0.1875&lt;BR /&gt;0 0.25&lt;BR /&gt;1 0.3125&lt;BR /&gt;0 0.375&lt;BR /&gt;1 0.4375&lt;BR /&gt;0 0.5&lt;BR /&gt;1 0.5625&lt;BR /&gt;0 0.625&lt;BR /&gt;0 0.6875&lt;BR /&gt;1 0.75&lt;BR /&gt;1 0.8125&lt;BR /&gt;0 0.875&lt;BR /&gt;1 0.9375&lt;BR /&gt;;&lt;BR /&gt;proc sort data=work.default;&lt;BR /&gt;by descending Data;&lt;BR /&gt;run;&lt;BR /&gt;data work.cumulative;&lt;BR /&gt;set work.default;&lt;BR /&gt;NonDefault=1-Default;&lt;BR /&gt;by data notsorted;&lt;BR /&gt;if first.id then defaultRate=0;&lt;BR /&gt;defaultRate+default;&lt;BR /&gt;if first.id then NondefaultRate=0;&lt;BR /&gt;NondefaultRate+Nondefault;&lt;BR /&gt;run;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table work.cumulative2 as&lt;BR /&gt;select default,data,NonDefault,defaultRate,NondefaultRate,sum(default) as TotalDefault,sum(NonDefault) as TotalNonDefault&lt;BR /&gt;from work.cumulative;&lt;BR /&gt;quit;&lt;BR /&gt;data work.cumulativeResult;&lt;BR /&gt;set work.cumulative2 END=lastN;&lt;BR /&gt;ResultD=defaultRate/TotalDefault;&lt;BR /&gt;ResultND=NondefaultRate/TotalNonDefault;&lt;BR /&gt;Retain Sonuc 0;&lt;BR /&gt;/*IF _n_=1 then Area=(ResultND/2)*ResultD;&lt;BR /&gt;ELSE*/Area=(ResultND+Lag(ResultND))/2*(ResultD-Lag(ResultD));&lt;BR /&gt;IF missing(Area)=1 then Area2=0;&lt;BR /&gt;Else Area2=Area;&lt;BR /&gt;Sonuc=Sonuc+Area2;&lt;BR /&gt;run;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table cumulativeResultMax as&lt;BR /&gt;select max(Sonuc) as MaxSonuc&lt;BR /&gt;from cumulativeResult;&lt;BR /&gt;quit;&lt;BR /&gt;data PowerStat;&lt;BR /&gt;set work.cumulativeresultmax;&lt;BR /&gt;PowerStat=(MaxSonuc-0.5)*2;&lt;BR /&gt;ABSResult=ABS(PowerStat);&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Sep 2015 19:47:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Less-Data-Step-amp-less-proc-sql-posibilites-to-get-same-result/m-p/225692#M40534</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2015-09-15T19:47:12Z</dc:date>
    </item>
    <item>
      <title>Re: Less Data Step &amp; less proc sql posibilites to get same result</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Less-Data-Step-amp-less-proc-sql-posibilites-to-get-same-result/m-p/225727#M40550</link>
      <description>&lt;P&gt;You can replace your last 3 steps with this. Essentially, calculate the max within the data step and then generate your final result at the end of the data step.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data PowerStat;
set work.cumulative2 END=lastN;
ResultD=defaultRate/TotalDefault;
ResultND=NondefaultRate/TotalNonDefault;
Retain Sonuc 0 MaxSonuc 0;
/*IF _n_=1 then Area=(ResultND/2)*ResultD;
ELSE*/Area=(ResultND+Lag(ResultND))/2*(ResultD-Lag(ResultD));
IF missing(Area)=1 then Area2=0;
Else Area2=Area;
Sonuc=Sonuc+Area2;
if Sonuc&amp;gt;maxSOnuc then maxsonuc=sonuc;

if lastN then do;
PowerStat=(MaxSonuc-0.5)*2;
ABSResult=ABS(PowerStat);
output;
keep maxsonuc powerstat absresult;
end;

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 15 Sep 2015 22:08:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Less-Data-Step-amp-less-proc-sql-posibilites-to-get-same-result/m-p/225727#M40550</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-09-15T22:08:02Z</dc:date>
    </item>
    <item>
      <title>Re: Less Data Step &amp; less proc sql posibilites to get same result</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Less-Data-Step-amp-less-proc-sql-posibilites-to-get-same-result/m-p/225741#M40558</link>
      <description>&lt;P&gt;Thanks a lot &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; Why i can't calculate Sum function at data step ? After this solution how can i take this values into new table with loop ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;These can probably help me but i can't handle it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let colCnt=&amp;lt;possibleValue&amp;gt;;&lt;/P&gt;&lt;P&gt;data out_data(keep=variable)&lt;/P&gt;&lt;P&gt;set work.new;&lt;/P&gt;&lt;P&gt;do i=1 to &amp;amp;colcnt.;&lt;/P&gt;&lt;P&gt;&amp;lt;????&amp;gt;&lt;BR /&gt;output;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro loop;&lt;BR /&gt;%let i=1;&lt;BR /&gt;%do %while(%scan(&amp;amp;VARNAME.,&amp;amp;i.,%STR( ))~=);&lt;BR /&gt;%procfreq(%scan(&amp;amp;VARNAME.,&amp;amp;i.,%STR( )));&lt;BR /&gt;%let i=&amp;amp;i.+1;&lt;BR /&gt;%end;&lt;BR /&gt;%mend;&lt;BR /&gt;%loop;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Sep 2015 23:22:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Less-Data-Step-amp-less-proc-sql-posibilites-to-get-same-result/m-p/225741#M40558</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2015-09-15T23:22:44Z</dc:date>
    </item>
    <item>
      <title>Re: Less Data Step &amp; less proc sql posibilites to get same result</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Less-Data-Step-amp-less-proc-sql-posibilites-to-get-same-result/m-p/225746#M40560</link>
      <description>You can calculate sum at a data step level but its more complex and requires a DOW loop. That being said, I didn't thoroughly go over your program. I don't understand your next question. And since it looks unrelated I'll suggest posting a new question. L</description>
      <pubDate>Wed, 16 Sep 2015 00:15:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Less-Data-Step-amp-less-proc-sql-posibilites-to-get-same-result/m-p/225746#M40560</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-09-16T00:15:42Z</dc:date>
    </item>
  </channel>
</rss>

