<?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 Sorting The Descending Way Cumulatively and Adding and Substracting Two Successive Rows in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Sorting-The-Descending-Way-Cumulatively-and-Adding-and/m-p/230113#M41714</link>
    <description>&lt;P&gt;&lt;SPAN&gt;Hello everyone,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I have listed &lt;/SPAN&gt;&lt;SPAN&gt;Frequency_Good , Frequency_Bad, Frequency_Density columns cumulatively as you can see on the code below. How can i list these three columns in the opposite order without effectint the other columns.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Also, I would like to add the GoodCase column with the GoodCase&amp;nbsp;next row and remove BadCase column from the BadCase&amp;nbsp;next row. How can i create these two columns into a new column?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Sample;
length ND 8 D 8;
infile datalines missover dlm=",";
input ND D;
datalines;
21165,58
6307,23
6943,35
11653,57
17285,163
20045,236
20094,343
21978,393
23882,554
21647,576
16383,450
12641,357
7844,256
4530,163
2468,110
1105,44
448,29
370,34
300,33
250,28
200,27
150,15
;
data Sample2;
	set Sample;
Total=ND+D;
run;
Proc sql;
Create table Sample3 as
select ND,D,Total,Sum(ND) AS TotalND,Sum(D) as TotalD, Sum(Total) AS TotTotal
from Sample2;
quit;
data Sample4(drop=TotalD TotalND TotTotal);
 set sample3;
 Rating_Class=Total/TotTotal;
 IF D=0 then DefaultRate=0;
 else DefaultRate=D/Total;
 Good_Case=ND/TotalND;
 Bad_Case=D/TotalD;
 Density_Function=Total/TotTotal;
Frequency_Good+Good_Case;
Frequency_Bad+Bad_Case;
Frequency_Density+Density_Function;
 run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;Thank you.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 15 Oct 2015 16:01:21 GMT</pubDate>
    <dc:creator>turcay</dc:creator>
    <dc:date>2015-10-15T16:01:21Z</dc:date>
    <item>
      <title>Sorting The Descending Way Cumulatively and Adding and Substracting Two Successive Rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sorting-The-Descending-Way-Cumulatively-and-Adding-and/m-p/230113#M41714</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Hello everyone,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I have listed &lt;/SPAN&gt;&lt;SPAN&gt;Frequency_Good , Frequency_Bad, Frequency_Density columns cumulatively as you can see on the code below. How can i list these three columns in the opposite order without effectint the other columns.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Also, I would like to add the GoodCase column with the GoodCase&amp;nbsp;next row and remove BadCase column from the BadCase&amp;nbsp;next row. How can i create these two columns into a new column?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Sample;
length ND 8 D 8;
infile datalines missover dlm=",";
input ND D;
datalines;
21165,58
6307,23
6943,35
11653,57
17285,163
20045,236
20094,343
21978,393
23882,554
21647,576
16383,450
12641,357
7844,256
4530,163
2468,110
1105,44
448,29
370,34
300,33
250,28
200,27
150,15
;
data Sample2;
	set Sample;
Total=ND+D;
run;
Proc sql;
Create table Sample3 as
select ND,D,Total,Sum(ND) AS TotalND,Sum(D) as TotalD, Sum(Total) AS TotTotal
from Sample2;
quit;
data Sample4(drop=TotalD TotalND TotTotal);
 set sample3;
 Rating_Class=Total/TotTotal;
 IF D=0 then DefaultRate=0;
 else DefaultRate=D/Total;
 Good_Case=ND/TotalND;
 Bad_Case=D/TotalD;
 Density_Function=Total/TotTotal;
Frequency_Good+Good_Case;
Frequency_Bad+Bad_Case;
Frequency_Density+Density_Function;
 run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;Thank you.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Oct 2015 16:01:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sorting-The-Descending-Way-Cumulatively-and-Adding-and/m-p/230113#M41714</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2015-10-15T16:01:21Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting The Descending Way Cumulatively and Adding and Substracting Two Successive Rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sorting-The-Descending-Way-Cumulatively-and-Adding-and/m-p/230146#M41723</link>
      <description>&lt;P&gt;Having&amp;nbsp;some problem following you.&lt;/P&gt;&lt;P&gt;Attach sample input (FREQ output) and wanted outcome.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Oct 2015 19:42:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sorting-The-Descending-Way-Cumulatively-and-Adding-and/m-p/230146#M41723</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2015-10-15T19:42:00Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting The Descending Way Cumulatively and Adding and Substracting Two Successive Rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sorting-The-Descending-Way-Cumulatively-and-Adding-and/m-p/230288#M41748</link>
      <description>&lt;P&gt;I solved the '&lt;SPAN&gt;Adding and Substracti&lt;/SPAN&gt;&lt;WBR /&gt;&lt;SPAN&gt;ng Two Successive Rows' question like as below. But i still didn't create the column&amp;nbsp;as cumulative. I added the data set image below. I created the columns as cumulative but I need to sort opposite of the last three columns.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;good_case_lag=lag(good_case);
bad_case_lag=lag(bad_case);
good_case2=sum(good_case,good_case_lag);
bad_case2=sum(bad_case_lag,-1*bad_case);&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/517i11CC08154C246029/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" alt="Cumulative.png" title="Cumulative.png" /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Oct 2015 13:57:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sorting-The-Descending-Way-Cumulatively-and-Adding-and/m-p/230288#M41748</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2015-10-16T13:57:59Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting The Descending Way Cumulatively and Adding and Substracting Two Successive Rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sorting-The-Descending-Way-Cumulatively-and-Adding-and/m-p/234337#M42849</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13674"&gt;@LinusH﻿&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Firstly, i added obsnum column by using _n_ option and sort the column by descending after that i create three cumulative columns. Please check the code if you agree i will accept the answer as solved.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13674"&gt;@LinusH﻿&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data dataset;
set dataset2;
obsnum=_n_; 
...
...
...
run;

proc sort data=dataset2 out=dataset3(keep=obsnum Column1);
by descending obsnum;
run;

data dataset3;
set dataset3;
CumColumn1+Column1;
run;

proc sort data=dataset3;
by obsnum;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Nov 2015 08:02:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sorting-The-Descending-Way-Cumulatively-and-Adding-and/m-p/234337#M42849</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2015-11-12T08:02:57Z</dc:date>
    </item>
  </channel>
</rss>

