<?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: Area under the curve calculation in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Area-under-the-curve-calculation/m-p/481956#M124756</link>
    <description>&lt;P&gt;One way:&lt;/P&gt;
&lt;PRE&gt;data want;
   set have;
   by id;
   retain area;
   lt = lat(time);
   lc = lag(concentration);
   if first.id then area=0;
   else area = area + (time - lt)*mean(concentration, lc);
run;&lt;/PRE&gt;
&lt;P&gt;Area here is the cumulative area and the last value of Id has to total.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You didn't show what the output should look like. If you only want final total then add : If last.id; to the end of the code.&lt;/P&gt;</description>
    <pubDate>Fri, 27 Jul 2018 17:53:05 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2018-07-27T17:53:05Z</dc:date>
    <item>
      <title>Area under the curve calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Area-under-the-curve-calculation/m-p/481913#M124738</link>
      <description>&lt;P&gt;Hello I have a set of data, I need to calculate the Area Under the Curve, how can I achieve that in SAS?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ID&lt;/TD&gt;&lt;TD&gt;Time&lt;/TD&gt;&lt;TD&gt;Concentration&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;1.120540964&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;0.581928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&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;32&lt;/TD&gt;&lt;TD&gt;0.367260062&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;36&lt;/TD&gt;&lt;TD&gt;0.935178019&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;40&lt;/TD&gt;&lt;TD&gt;1.938660991&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;44&lt;/TD&gt;&lt;TD&gt;0.949690402&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;48&lt;/TD&gt;&lt;TD&gt;1.617066563&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Fri, 27 Jul 2018 15:48:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Area-under-the-curve-calculation/m-p/481913#M124738</guid>
      <dc:creator>Aridany</dc:creator>
      <dc:date>2018-07-27T15:48:16Z</dc:date>
    </item>
    <item>
      <title>Re: Area under the curve calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Area-under-the-curve-calculation/m-p/481917#M124739</link>
      <description>&lt;P&gt;What role does ID play in this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When you say "under the curve" do you mean under a smoothed curve going through those points or the sums of areas of the trapezoids defined by successive time values?&lt;/P&gt;</description>
      <pubDate>Fri, 27 Jul 2018 15:59:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Area-under-the-curve-calculation/m-p/481917#M124739</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-07-27T15:59:59Z</dc:date>
    </item>
    <item>
      <title>Re: Area under the curve calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Area-under-the-curve-calculation/m-p/481918#M124740</link>
      <description>&lt;P&gt;ID is the name is different subjects in my study. I prefer to have the area of the trapezoids&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Fri, 27 Jul 2018 16:01:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Area-under-the-curve-calculation/m-p/481918#M124740</guid>
      <dc:creator>Aridany</dc:creator>
      <dc:date>2018-07-27T16:01:57Z</dc:date>
    </item>
    <item>
      <title>Re: Area under the curve calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Area-under-the-curve-calculation/m-p/481925#M124742</link>
      <description>&lt;P&gt;Do you want this done for each id or as a whole?&lt;/P&gt;</description>
      <pubDate>Fri, 27 Jul 2018 16:18:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Area-under-the-curve-calculation/m-p/481925#M124742</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2018-07-27T16:18:13Z</dc:date>
    </item>
    <item>
      <title>Re: Area under the curve calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Area-under-the-curve-calculation/m-p/481926#M124743</link>
      <description>&lt;P&gt;For each ID, thank you&lt;/P&gt;</description>
      <pubDate>Fri, 27 Jul 2018 16:19:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Area-under-the-curve-calculation/m-p/481926#M124743</guid>
      <dc:creator>Aridany</dc:creator>
      <dc:date>2018-07-27T16:19:48Z</dc:date>
    </item>
    <item>
      <title>Re: Area under the curve calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Area-under-the-curve-calculation/m-p/481956#M124756</link>
      <description>&lt;P&gt;One way:&lt;/P&gt;
&lt;PRE&gt;data want;
   set have;
   by id;
   retain area;
   lt = lat(time);
   lc = lag(concentration);
   if first.id then area=0;
   else area = area + (time - lt)*mean(concentration, lc);
run;&lt;/PRE&gt;
&lt;P&gt;Area here is the cumulative area and the last value of Id has to total.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You didn't show what the output should look like. If you only want final total then add : If last.id; to the end of the code.&lt;/P&gt;</description>
      <pubDate>Fri, 27 Jul 2018 17:53:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Area-under-the-curve-calculation/m-p/481956#M124756</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-07-27T17:53:05Z</dc:date>
    </item>
    <item>
      <title>Re: Area under the curve calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Area-under-the-curve-calculation/m-p/482169#M124841</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt;&amp;nbsp;has written a blog about it .&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 28 Jul 2018 11:29:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Area-under-the-curve-calculation/m-p/482169#M124841</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-07-28T11:29:39Z</dc:date>
    </item>
    <item>
      <title>Re: Area under the curve calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Area-under-the-curve-calculation/m-p/482221#M124860</link>
      <description>&lt;P&gt;Since you specify "area under CURVE", I presume you want one observation per ID:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 input ID Time Concentration ;
datalines;
2  0 1.120540964 
2  4 0.581928655 
2  8 0.532928263 
2 12 0.366326931 
2 16 0.481379851 
2 20 0.614268914 
2 24 0.692669541 
2 28 0.340258722 
2 32 0.447275578 
2 36 0.394551156 
2 40 0.611916895 
2 44 0.611916895 
2 48 0.476871815 
3  0 1.466453674 
3  4 0.768142401 
3  8 0.464399817 
3 12 0.500912825 
3 16 0.751939754 
3 20 0.829758101 
3 24 0.81195801 
3 28 0.523505249 
3 32 0.508443633 
3 36 0.356230032 
3 40 0.306481059 
3 44 0.452304884 
3 48 0.329073482 
4  0 0.569163694 
4  4 0.423900119 
4  8 0.372968688 
4 12 0.503963535 
4 16 0.447483155 
4 20 0.760602457 
4 24 0.752080856 
4 28 1.273285771 
4 32 0.326397146 
4 36 0.448474039 
4 40 0.478596908 
4 44 0.714229092 
4 48 0.563416568 
5  0 0.829721362 
5  4 1.272832817 
5  8 0.621904025 
5 12 0.367840557 
5 16 0.47871517 
5 20 1.062113003 
5 24 0.796633127 
5 28 0.395123839 
5 32 0.367260062 
5 36 0.935178019 
5 40 1.938660991 
5 44 0.949690402 
5 48 1.617066563 
run;

data want (keep=id area);
  set have;
  by id;
  area + dif(time)*mean(concentration,lag(concentration));
  if first.id then area=0;
  if last.id;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The DIF function is equivalent to X-lag(X).&lt;/P&gt;</description>
      <pubDate>Sun, 29 Jul 2018 02:16:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Area-under-the-curve-calculation/m-p/482221#M124860</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2018-07-29T02:16:25Z</dc:date>
    </item>
    <item>
      <title>Re: Area under the curve calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Area-under-the-curve-calculation/m-p/482296#M124896</link>
      <description>&lt;P&gt;Thank you very much for your response, but the code doesn't work. this is the message that comes out. I'm really new in SAS, the only reason I use is because the pressure in my department, apparently if you don't use SAS you are not considerate an animal scientist&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;376&amp;nbsp; ;&lt;BR /&gt;377&lt;BR /&gt;378&amp;nbsp; data want (keep=id area);&lt;BR /&gt;379&amp;nbsp;&amp;nbsp;&amp;nbsp; set have;&lt;BR /&gt;380&amp;nbsp;&amp;nbsp;&amp;nbsp; by id;&lt;BR /&gt;381&amp;nbsp;&amp;nbsp;&amp;nbsp; area + dif(time)*mean(concentration,lag(concentration));&lt;BR /&gt;382&amp;nbsp;&amp;nbsp;&amp;nbsp; if first.id then area=0;&lt;BR /&gt;383&amp;nbsp;&amp;nbsp;&amp;nbsp; if last.id;&lt;BR /&gt;384&amp;nbsp; run;&lt;BR /&gt;&lt;BR /&gt;NOTE: Missing values were generated as a result of performing an operation on missing values.&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Each place is given by: (Number of times) at (Line):(Column).&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1 at 381:19&lt;BR /&gt;NOTE: There were 52 observations read from the data set WORK.HAVE.&lt;BR /&gt;NOTE: The data set WORK.WANT has 4 observations and 2 variables.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; real time&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.06 seconds&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cpu time&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.04 seconds&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 29 Jul 2018 16:02:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Area-under-the-curve-calculation/m-p/482296#M124896</guid>
      <dc:creator>Aridany</dc:creator>
      <dc:date>2018-07-29T16:02:22Z</dc:date>
    </item>
    <item>
      <title>Re: Area under the curve calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Area-under-the-curve-calculation/m-p/482328#M124905</link>
      <description>&lt;OL&gt;
&lt;LI&gt;Did you look at the data? If so, what's wrong with it?&lt;/LI&gt;
&lt;LI&gt;What about the log makes you think something is wrong?&amp;nbsp; Here's what I get from the&amp;nbsp; log:&lt;BR /&gt;
&lt;OL&gt;
&lt;LI&gt;52 observations were read in (i.e. 13 observations each for 4 id's).&lt;/LI&gt;
&lt;LI&gt;4 observations were written out - one per id, yielding the total area for each id.&lt;/LI&gt;
&lt;LI&gt;There is a note that a missing value was generated ONCE in line 381.&amp;nbsp; So the other 51 times line 381 was executed, a&amp;nbsp; missing value was NOT generated.&lt;BR /&gt;&lt;BR /&gt;What was that one time?&amp;nbsp;&amp;nbsp; Since the DIF function is defined as dif(x)=x-lag(x), then the missing value was generated for the first observation, since&amp;nbsp; lag(x) would be missing at the point.&lt;BR /&gt;&lt;BR /&gt;However, while a missing value is generated for the DIF(x) expression in observation 1, it's not propagated to area, because the statement is effectively &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; area + .&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (a summing statement)&lt;BR /&gt;rather than area=area+.&amp;nbsp;&amp;nbsp; (an assignment statement)&lt;BR /&gt;&lt;BR /&gt;The summing statement for obs 1 is &lt;BR /&gt;&amp;nbsp;&amp;nbsp; 0+.&lt;BR /&gt;which yields a 0 in observation 1.&lt;/LI&gt;
&lt;/OL&gt;
&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;So If there is a&amp;nbsp; problem, you need to be more specific about what it is.&lt;/P&gt;</description>
      <pubDate>Mon, 30 Jul 2018 01:01:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Area-under-the-curve-calculation/m-p/482328#M124905</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2018-07-30T01:01:50Z</dc:date>
    </item>
    <item>
      <title>Re: Area under the curve calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Area-under-the-curve-calculation/m-p/482586#M125028</link>
      <description>&lt;P&gt;Mark,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I agree that your program works. But I question whether it is correctly calculating the area under the curve.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I know better than to challenge you in a math competition but, years ago, I wrote programs in basic and fortran that calculated a Gini. Out of curiosity, I took the basic code and, without trying to optimize it, converted it so that it would run in SAS. I compared the results with some examples I found on the web (e.g., &lt;A href="https://www3.nd.edu/~wbrooks/GiniNotes.pdf" target="_blank"&gt;https://www3.nd.edu/~wbrooks/GiniNotes.pdf&lt;/A&gt; ).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My results matched their results, but didn't match the results obtained with your code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Am I missing something?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is what I ran:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input id time concentration;
  cards;
1 0.02 0.10 
1 0.03 0.05 
1 0.10 0.15 
1 0.50 0.50 
1 0.35 0.20
;

data want;
  set have (rename=(concentration=x time=y));
  if missing(y) then y=1;
  p=x/(x+y);
run;

proc sort data=want;
  by id descending p;
run;

data want;
  do until (last.id);
    set want;
    by id;
    if first.id then do;
      sumx=x;
      sumy=y;
    end;
    else do;
      sumx+x;
      sumy+y;
    end;
  end;
  do until (last.id);
    set want;
    by id;
    output;
  end;
run;

data want (keep=g s);
  set want;
  by id;
  if first.id then do;
    g=0;
    cumx=0;
    cumy=0;
  end;
  xpct=x/sumx;
  ypct=y/sumy;
  G+(((CUMY*2)+YPCT)*XPCT);
  CUMX+XPCT;
  CUMY+YPCT;
  S+ABS(XPCT-YPCT);
  if last.id then do;
    G=(1-G)*100;
    S=S*.5*100;
    output;
  end;
run;
&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, 30 Jul 2018 19:47:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Area-under-the-curve-calculation/m-p/482586#M125028</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2018-07-30T19:47:06Z</dc:date>
    </item>
    <item>
      <title>Re: Area under the curve calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Area-under-the-curve-calculation/m-p/482628#M125041</link>
      <description>&lt;P&gt;Art:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't think the OP here is asking for Gini&amp;nbsp; (area between a 45 degree line and a Lorenz curve connecting cumulative totals of ordered scores of the criterion variable).&amp;nbsp; So I wouldn't expect your program to produce the same value as my program above.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My code above is supposed to sum 12 trapezoids per ID, arising from 13 observations in sequence, where the trapezoid height is the diference in successive times, and the two bases are the current and previous concentration scores.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If there's a request for an overall measure of inequality in the distribution of the criterion, I totally missed it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;regards,&lt;/P&gt;
&lt;P&gt;Mark&lt;/P&gt;</description>
      <pubDate>Mon, 30 Jul 2018 22:09:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Area-under-the-curve-calculation/m-p/482628#M125041</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2018-07-30T22:09:21Z</dc:date>
    </item>
    <item>
      <title>Re: Area under the curve calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Area-under-the-curve-calculation/m-p/482630#M125042</link>
      <description>&lt;P&gt;@ Mark: I totally agree! Would you agree with the following?:&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/223300"&gt;@Aridany&lt;/a&gt;: The more I look at your data and question, I think that&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;'s approach will do what you want. I had been thinking about it like a Gini problem (i.e., a measure of inequality), but I don't think that is what it is.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You want to know the area under the curve, but you haven't indicated what is being plotted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The following is based on plotting percent of total concentration as a function of time (thus the total area of each plot would be 48). Without some kind of standardization like that, I'm not sure if the results for each id are comparable with each other:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data need (drop=total);
  do until (last.id);
    set have;
    by id;
    total+concentration;
  end;
  do until (last.id);
    set have;
    by id;
    pct=concentration/total;
    output;
  end;
run;

data want (keep=id area_below area_above);
  set need;
  by id;
  area_below + dif(time)*mean(pct,lag(pct));
  area_above + dif(time)*mean(1-pct,1-lag(pct));
  if first.id then do;
    area_below=0;
    area_above=0;
  end;
  if last.id;
run;
&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, 30 Jul 2018 22:15:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Area-under-the-curve-calculation/m-p/482630#M125042</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2018-07-30T22:15:18Z</dc:date>
    </item>
    <item>
      <title>Re: Area under the curve calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Area-under-the-curve-calculation/m-p/482659#M125060</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks everybody for the answers, it looks like you really know what you are saying. The biggest problem I have is I don't understand what you mean by "want", "need" and "have" code. I'm not a mathematician, I just need the area under the curve, I don't understand all that you are saying, so I'm going to use Excel to calculate that. I prefer to be a weirdo in my department for not using SAS than kill myself trying to understand what you all are saying. Thanks again all for your effort. Really surprised me how much you know. Impressive. I prefer to keep using statistic packages more user frendly like Minitab or SPSS.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Have a great day,&lt;/P&gt;&lt;P&gt;Ary&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jul 2018 00:23:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Area-under-the-curve-calculation/m-p/482659#M125060</guid>
      <dc:creator>Aridany</dc:creator>
      <dc:date>2018-07-31T00:23:22Z</dc:date>
    </item>
    <item>
      <title>Re: Area under the curve calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Area-under-the-curve-calculation/m-p/482673#M125066</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/223300"&gt;@Aridany&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;WANT, NEED, HAVE.&amp;nbsp; This is not a sas-specific terminology. nor is it mathematical.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As a problem generalization, the user typically has a dataset, which we generically call HAVE.&amp;nbsp; And the user&amp;nbsp;commonly desires to produce results in the form of another datasets,&amp;nbsp;which we generically call WANT.&amp;nbsp;&amp;nbsp; And sometimes you must create an intermediate data set to solve the problem in two steps instead of one.&amp;nbsp; We generically call that NEED.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you had created your own dataset name when you posed the problem, we may very well have used those names instead.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You didn't specify how you wanted the result (as a printable file, or a data set), which I think is understandable.&amp;nbsp; However, you apparently didn't look at the resulting dataset that my code produced.&amp;nbsp; And only now do I think that you wanted the area-under-curve printed out in the log or listing as opposed to being stored in a data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;User-friendliness, even in SAS, can benefit from clarifying the problem statement when&amp;nbsp;respondents generate something other than what you want.&amp;nbsp; Mutual patience can be rewarding.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jul 2018 02:32:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Area-under-the-curve-calculation/m-p/482673#M125066</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2018-07-31T02:32:19Z</dc:date>
    </item>
    <item>
      <title>Re: Area under the curve calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Area-under-the-curve-calculation/m-p/650083#M194937</link>
      <description>&lt;P&gt;Hi...I'm also dealing with the same questions..&lt;/P&gt;&lt;P&gt;So I'll post to ussufull approaches:&lt;/P&gt;&lt;P&gt;1) In SAS/STAT, use data statement:&amp;nbsp;&lt;BR /&gt;&lt;A href="https://www.lexjansen.com/wuss/2004/posters/c_post_the_sas_calculations_.pdf" target="_blank"&gt;https://www.lexjansen.com/wuss/2004/posters/c_post_the_sas_calculations_.pdf&lt;/A&gt;&lt;/P&gt;&lt;P&gt;2) I&lt;SPAN&gt;n SAS/ETS, use PROC EXPAND &amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://support.sas.com/kb/24/990.html" target="_blank"&gt;https://support.sas.com/kb/24/990.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 23 May 2020 12:48:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Area-under-the-curve-calculation/m-p/650083#M194937</guid>
      <dc:creator>ptadger</dc:creator>
      <dc:date>2020-05-23T12:48:34Z</dc:date>
    </item>
  </channel>
</rss>

