BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
philip_
Fluorite | Level 6

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)?

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

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

4 REPLIES 4
PGStats
Opal | Level 21

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
philip_
Fluorite | Level 6

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.

PGStats
Opal | Level 21

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
Rick_SAS
SAS Super FREQ

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 (.).

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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