DATA Step, Macro, Functions and more

Evaluate normal quantile function at 1 or 0

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 7
Accepted Solution

Evaluate normal quantile function at 1 or 0

I am trying to translate code from R into SAS. In R I can evaluate the normal quantile function on the [0,1] intervall. E.g.

qnorm(1)
[1] Inf

However, if I do this in SAS with the following code

y=QUANTILE("NORMAL", 1);

I get an error message and the result is a missing value. (Note: between 0 and 1 the function works fine)

 

Is there a possibility to get Inf (.I) as a result (without manually capturing the cases)?


Accepted Solutions
Solution
‎12-20-2016 07:29 AM
SAS Super FREQ
Posts: 3,489

Re: Evaluate normal quantile function at 1 or 0

Your quote is from the SAS/IML documentation and it probably refers to the use of .M and .P as endpoints for numerical integration on infinite domains, as implemented in the QUAD subroutine.

 

Mathematically, the domain of a quantile function is the open interval (0, 1). You can trap out-of-domain errors by using the ideas in the article "Trap and cap: Avoid division by zero and domain errors when evaluating functions." For quantiles, it might look like this:

 

   data Q;
   input prob @@;
   if prob <=0 then q = .M; 
   else if prob>=1 then q = .P;
   else q = quantile("Normal", prob);
   datalines;
   -1 0 .1 .5 .9 1 1.2
   ;

   proc print; run;

You could also define a user-defined format to print .M as "-Infinity" and .P as "+Infinity."

 

Traditional SAS supports 27 missing value: ., ._, and .A, ..., .Z. You can choose to interpret these missing values any way you want in your programs. However, most numerical functions (SQRT, LOG, EXP,...) accept any missing value and return the generic missing value (.).

 

View solution in original post


All Replies
Respected Advisor
Posts: 4,663

Re: Evaluate normal quantile function at 1 or 0

You could write your own qnorm() with FCMP. However, I don't know that SAS handles ".I" any differently than other missing values, including ".".

PG
Occasional Contributor
Posts: 7

Re: Evaluate normal quantile function at 1 or 0

PG, thanks for your reply. Regarding ".I", I misinterpreted this link: http://support.sas.com/documentation/cdl/en/imlug/63541/HTML/default/viewer.htm#imlug_r_sect019.htm. It states: "Some applications use .I to represent positive infinity and use .M to represent negative infinity."

 

But this brings me to a closely related question: Is there a symbol in SAS for infinity and could SAS handle inifity as an input? E.g. is something like this possible: CDF("Normal", infinity) which I expect to return 1.

 

Thanks in advance.

Respected Advisor
Posts: 4,663

Re: Evaluate normal quantile function at 1 or 0

To my knowledge, only the DIVIDE function handles .I and .M in a special way. Everywhere in SAS Base, the values . and .A-.Z are treated as missing values. You could say that SAS has adopted a pragmatic approach to computation. It is limited to finite values that can be represented with the floating point hardware :

 

26   data _null_;
27   ataninf = atan(.i);
28   expminf = exp(.m);
29   expmlarge = exp(-1e200);
30   isZero = expmlarge = 0;
31   put ataninf= expminf= expmlarge= iszero=;
32   run;

ataninf=. expminf=. expmlarge=0 isZero=1
PG
Solution
‎12-20-2016 07:29 AM
SAS Super FREQ
Posts: 3,489

Re: Evaluate normal quantile function at 1 or 0

Your quote is from the SAS/IML documentation and it probably refers to the use of .M and .P as endpoints for numerical integration on infinite domains, as implemented in the QUAD subroutine.

 

Mathematically, the domain of a quantile function is the open interval (0, 1). You can trap out-of-domain errors by using the ideas in the article "Trap and cap: Avoid division by zero and domain errors when evaluating functions." For quantiles, it might look like this:

 

   data Q;
   input prob @@;
   if prob <=0 then q = .M; 
   else if prob>=1 then q = .P;
   else q = quantile("Normal", prob);
   datalines;
   -1 0 .1 .5 .9 1 1.2
   ;

   proc print; run;

You could also define a user-defined format to print .M as "-Infinity" and .P as "+Infinity."

 

Traditional SAS supports 27 missing value: ., ._, and .A, ..., .Z. You can choose to interpret these missing values any way you want in your programs. However, most numerical functions (SQRT, LOG, EXP,...) accept any missing value and return the generic missing value (.).

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 241 views
  • 3 likes
  • 3 in conversation