<?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: How to cap a curve by another curve in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-cap-a-curve-by-another-curve/m-p/338096#M76879</link>
    <description>&lt;P&gt;Here is a way using &lt;STRONG&gt;proc expand&lt;/STRONG&gt;:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data original_curve;
input x1 y1;
datalines;
0   0
200 100
300 200
run;

data cap_curve;
input x2 y2;
datalines;
0   50
130 50
250 210
300 210
;

data all_c;
merge 
    original_curve(rename=x1=x) 
    cap_curve(rename=x2=x);
by x;
run;

proc expand data=all_c out=all_int;
id x;
convert y1 y2 / method=join;
run;

data capped_curve;
retain xp yp1 yp2;
set all_int(rename=(x=xc y1=yc1 y2=yc2));
if _n_ &amp;gt; 1 then do;
    if (yc1&amp;gt;yc2) ne (yp1&amp;gt;yp2) then do;
        a = (yc2-yc1) / (yc2-yc1+yp1-yp2);
        x3 = a*xp + (1-a)*xc;
        y3 = a*yp1 + (1-a)*yc1;
        output;
        end;
    end;
x3 = xc;
y3 = min(yc1, yc2);
output;
xp = xc;
yp1 = yc1;
yp2 = yc2;
keep x3 y3;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 04 Mar 2017 06:25:20 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2017-03-04T06:25:20Z</dc:date>
    <item>
      <title>How to cap a curve by another curve</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-cap-a-curve-by-another-curve/m-p/338090#M76875</link>
      <description>&lt;P&gt;original_curve and cap_curve are inputs.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The original_curve is capped by the cap_curve, and the output is the capped_curve.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How to use SAS to create the capped_curve based on the original_curve and cap_curve?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;IMG title="cap_curve.png" alt="cap_curve.png" src="https://communities.sas.com/t5/image/serverpage/image-id/7565i313410ED6ED2AF62/image-size/original?v=1.0&amp;amp;px=-1" border="0" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;PRE&gt;data original_curve;
input x1 y1;
datalines;
0   0
200 100
300 200
run;

data cap_curve;
input x2 y2;
datalines;
0   50
130 50
250 210
300 210
;

data capped_curve;
input x3 y3;
datalines;
0   0
100 50
130 50
148 74
200 100
300 200
;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 04 Mar 2017 04:27:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-cap-a-curve-by-another-curve/m-p/338090#M76875</guid>
      <dc:creator>jjjch</dc:creator>
      <dc:date>2017-03-04T04:27:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to cap a curve by another curve</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-cap-a-curve-by-another-curve/m-p/338095#M76878</link>
      <description>&lt;P&gt;Change your CAP curve to a different format:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;start end max_value&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then merge second table on the condition that&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Proc sql;&lt;/P&gt;
&lt;P&gt;create table want as&amp;nbsp;&lt;/P&gt;
&lt;P&gt;select a.x1, min(b.max_value, a.y1) as capped_value&lt;/P&gt;
&lt;P&gt;from tableA as a&lt;/P&gt;
&lt;P&gt;left join tableB as b on&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A.x1 between start and end;&lt;/P&gt;
&lt;P&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm not sure how you determined the values to belong to the third table but this should help you get the idea.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 04 Mar 2017 06:22:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-cap-a-curve-by-another-curve/m-p/338095#M76878</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-03-04T06:22:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to cap a curve by another curve</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-cap-a-curve-by-another-curve/m-p/338096#M76879</link>
      <description>&lt;P&gt;Here is a way using &lt;STRONG&gt;proc expand&lt;/STRONG&gt;:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data original_curve;
input x1 y1;
datalines;
0   0
200 100
300 200
run;

data cap_curve;
input x2 y2;
datalines;
0   50
130 50
250 210
300 210
;

data all_c;
merge 
    original_curve(rename=x1=x) 
    cap_curve(rename=x2=x);
by x;
run;

proc expand data=all_c out=all_int;
id x;
convert y1 y2 / method=join;
run;

data capped_curve;
retain xp yp1 yp2;
set all_int(rename=(x=xc y1=yc1 y2=yc2));
if _n_ &amp;gt; 1 then do;
    if (yc1&amp;gt;yc2) ne (yp1&amp;gt;yp2) then do;
        a = (yc2-yc1) / (yc2-yc1+yp1-yp2);
        x3 = a*xp + (1-a)*xc;
        y3 = a*yp1 + (1-a)*yc1;
        output;
        end;
    end;
x3 = xc;
y3 = min(yc1, yc2);
output;
xp = xc;
yp1 = yc1;
yp2 = yc2;
keep x3 y3;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 04 Mar 2017 06:25:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-cap-a-curve-by-another-curve/m-p/338096#M76879</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2017-03-04T06:25:20Z</dc:date>
    </item>
  </channel>
</rss>

