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)?
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 (.).
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, 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.
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
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 (.).
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.