I need to create a cumulative distribution function (F) of the Gamma(a,b) distribution and then use this function to calculate Ws which I have noted profil_W in my program.
Here is the calculation formula for profil_W.
Profile_W=(k*F(k)+(k-2)*F(k-2))+(k-1)*F(k-1)+ab(2*F(k-1)-F( k-2)-F(k)).
The first part F follows the Gamma(a,b) law and the second part F follows the Gamma(a+1,b) law.
Note that the second part begins with ab(...).
Here is the code to calculate the 2 laws of Gamma followed by F that I noted "Fct_ab" the first and "Fct_A1b" the second.
k represents "Incid" in my formula. My problem is that I can't vary or calculate the functions F(k), F(k-1), F(k-2), etc.
Here is the code:
/*----------------------------------------------*/
proc contents date= tab_It;
run;
/*Fixed Gamma Law Parameter*/
%let a=1;
%let b=5;
/*Distribution of the Gamma(a,b) distribution*/
Data tab_W;
set tab_It;
if (%sysevalf(&b.)>0) and (%sysevalf(&b.)>0) ;
if (Incid >0);
Fct_ab=RAND('GAMMA', %sysevalf(&a.), %sysevalf(&b.));
Fct_A1b=RAND('GAMMA', %sysevalf(&a.)+1, %sysevalf(&b.));
profil_W=round((Incid*(Fct_ab)+(Incid-2)*Fct_ab-2*(Incid-1)*Fct_ab) +%sysevalf(&a.)*%sysevalf(&b.)*(2*Fct_A1b-Fct_A1b),0.01);
run;
If a macro variable contains a value that is easily considered as a number you do not need all that %syseval junk.
Example:
%let a= 0.25; %let b= 4; data example; x = &a. * &b.; run;
which results in the expected 1 for x. All macro variables are is text. If the value you have would be okay for a statement as is such as : x = 0.25 * 4 ; then that's all you need.
The function CDF in SAS returns a value from the cumulative distribution, the Quantile function returns a specific point from the distribution. Rand generates a random number from from the distribution so I doubt that is what you want.
"Generate a distribution" I would typically take to create fair portion of values from a distribution, not a single value as your code does. So I suspect that you need to provide more details. Possibly provide a link to what you mean by "Gamma law" as most of the internet search results I get are company names, gaming or image color correction related.
Time to start over. I know what a Gamma distribution is. Neither of the links you provide have anything related to "Gamma Law"
Your request starts with
I need to create a cumulative distribution function (F) of the Gamma(a,b) distribution and then use this function to calculate
You do not need to create a CDF for the gamma function. SAS provides two functions, one of which is very likely what you want either CDF or QUANTILE.
CDF would involve writing code to implement and calculate integrals. Which you have not shown even a slight attempt to do so. I have done such code but refuse to do for functions that SAS Provides and except for nearly-trivial examples wouldn't on this forum as the amount of work is excessive for a volunteer.
Look at the documentation for the CDF function,
Returns a value from a cumulative probability distribution.
X would be the point of the cumulative you are specifically interested in which could be a variable or fixed value, your choice.
If that is not what you want then likely the Quantile function is what you want.
As long as your K has the appropriate value then that is likely the correct call.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.