BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
imanojkumar1
Quartz | Level 8

For the following data, what I am trying to learn are:

 

1. plot and find area under the curve (which is calculated using either 1. Simpson's rule (https://en.wikipedia.org/wiki/Simpson%27s_rule) or, 2. Trapezoidal rule (https://en.wikipedia.org/wiki/Trapezoidal_rule)  - Not sure if there are SAS's inbuilt functions for that.

 

2. Find the mid point on the plot, divide the plot into two 'A' and 'B' and then divide each of 'A' and 'B' in equal smaller segments (like black lines on the plot for section 'A' shown in the below pic, and calculate area for each segment (say Seg1 = xx  mm2, Seg1 = xx1  mm2 and so forth)

 

sas.png

 

data sample;
infile cards truncover expandtabs;
input X Y;
cards;
29 21
18 23
28 24
16 26
3 27
18 29
2 33
3 37
26 39
2 42
25 47
9 54
13 57
17 58
29 60
5 63
23 66
4 69
3 72
17 73
7 73
12 72
8 69
20 66
12 63
8 60
28 58
3 57
18 54
11 47
21 42
8 39
1 37
16 29
3 27
17 22
3 19
6 17
19 14
18 10
;
run;

 

I was trying something like this...

 

data Trapezoidal;
    set x_y end=last;
    retain integral;
    lag_x=lag(x); lag_y = lag(y);
    if _N_ eq 1 then integral = 0;
    else integral = integral + (x - lag_x) * (y + lag_y) / 2;
run;

 

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

Because that would be messed up . 

Really suggest you post it at ODS Graphic forum.




data sample;
infile cards truncover expandtabs;
input X Y;
cards;
29 21
18 23
28 24
16 26
3 27
18 29
2 33
3 37
26 39
2 42
25 47
9 54
13 57
17 58
29 60
5 63
23 66
4 69
3 72
17 73
7 73
12 72
8 69
20 66
12 63
8 60
28 58
3 57
18 54
11 47
21 42
8 39
1 37
16 29
3 27
17 22
3 19
6 17
19 14
18 10
;
run;

proc sort data=sample ;
by x;
run;
proc sql;
select mean(x) into : x from sample ;
quit;
proc sgplot data=sample;
needle x=x y=y;
spline x=x y=y / lineattrs=graphdata4(thickness=4);
refline &x / axis=x lineattrs=(color=red thickness=4);
run;

data Trapezoidal;
    set sample end=last;
    dif_x=dif(x); 
    mean_y=mean(lag(y),y);
    integral + (dif_x*mean_y);
    if last then putlog 'area under curve is ' integral;
run;

View solution in original post

3 REPLIES 3
Ksharp
Super User

data sample;
infile cards truncover expandtabs;
input X Y;
cards;
29 21
18 23
28 24
16 26
3 27
18 29
2 33
3 37
26 39
2 42
25 47
9 54
13 57
17 58
29 60
5 63
23 66
4 69
3 72
17 73
7 73
12 72
8 69
20 66
12 63
8 60
28 58
3 57
18 54
11 47
21 42
8 39
1 37
16 29
3 27
17 22
3 19
6 17
19 14
18 10
;
run;

proc sort data=sample ;
by x;
run;

proc sgplot data=sample;
needle x=x y=y;
run;

data Trapezoidal;
    set sample end=last;
    dif_x=dif(x); 
    mean_y=mean(lag(y),y);
    integral + (dif_x*mean_y);
    if last then putlog 'area under curve is ' integral;
run;

imanojkumar1
Quartz | Level 8
Thanks for your help KSharp. I am just wondering why needle chart used and not line plot. Also, can we plot a vertical line (on X axis, at Y=MaxVal) in the middle of the plot.
Ksharp
Super User

Because that would be messed up . 

Really suggest you post it at ODS Graphic forum.




data sample;
infile cards truncover expandtabs;
input X Y;
cards;
29 21
18 23
28 24
16 26
3 27
18 29
2 33
3 37
26 39
2 42
25 47
9 54
13 57
17 58
29 60
5 63
23 66
4 69
3 72
17 73
7 73
12 72
8 69
20 66
12 63
8 60
28 58
3 57
18 54
11 47
21 42
8 39
1 37
16 29
3 27
17 22
3 19
6 17
19 14
18 10
;
run;

proc sort data=sample ;
by x;
run;
proc sql;
select mean(x) into : x from sample ;
quit;
proc sgplot data=sample;
needle x=x y=y;
spline x=x y=y / lineattrs=graphdata4(thickness=4);
refline &x / axis=x lineattrs=(color=red thickness=4);
run;

data Trapezoidal;
    set sample end=last;
    dif_x=dif(x); 
    mean_y=mean(lag(y),y);
    integral + (dif_x*mean_y);
    if last then putlog 'area under curve is ' integral;
run;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 1116 views
  • 2 likes
  • 2 in conversation