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 (.).
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.