*The simulation derivation step must be smaller than the threshold value, in order to obtain the accurate result; Data derivation (keep=interval slope); * functionY= 1/X onlyConcern about X>0; DeltaX=1e-6;*the step that X1 decreases when the secant becomes tangent; X0= 2; Y0= 0;%function(y0,x0);*points to be required for guidance; Put y0; Slope= 0;*the slope to be calculated, that is, the reciprocal; Interval= 5;*The distance between x0 and X1 in the x-axis is also the variable that determines the stop derivation; X1=X0+Interval Y1= 0;%function(Y1,X1);*The point at the other end of the secant, auxiliary derivative point; Thershold=1e-6 -1e-7;*the threshold for stopping the derivation; Do Until (interval<thershold); Interval=Interval-DeltaX;*update the spacing between x0 and X1; X1=X0+Interval%function(Y1,X1);*Update the coordinates of the X1; Slope=(y1-y0)/(x1-x0);*update slope, that is, countdown; Output End; run;/*here is any function you need to ask for, SAS is using the updated policy, so you don't need to write the return value*/%Macrofunction(Y,X); &Y= 1 / &x;%Mend
SAS simulation for derivation of arbitrary function