BookmarkSubscribeRSS Feed
Quartz | Level 8


I would like to define a function which will return log() only for positive values. If values are less than or equal to 0 then it should delete the observations.

Below are the codes I have tried. Correct me where I am going wrong.


proc fcmp outlib=work.Validlog.MathFuncs;
function Vlog(y);
if y>0 then return( log(y));else delete;


options cmplib=work.Validlog;
data values;
input x;



Super User

I think you would be better off with datastep to remove the observations:


data want;

    set have;

    if x le 0 then delete;

    else sf=vlog(x);



I am assuming you actually want to do more otherwise the complexity of setting up a call a function to replcace a SAS function is introducing unneeded complexity to a program.


Data is intended to be passed to and returned from the function. Since DELETE would affect variables not explicitly passed to the function (ie everything in that observation)that doesn't make sense for a functions behavior.

if you mean to return a MISSING value, which makes sense then instead of DELETE


proc fcmp outlib=work.Validlog.MathFuncs;
function Vlog(y);
if y>0 then return( log(y));

else return(.);

Rhodochrosite | Level 12

Instinctively I'd go with @ballardw and say id wouldn't make sense to support DELETE in FCMP. And indeed using it results in a run-time (not compile time!) error:


ERROR: Parsing error generating code.

However, I tried to find support for this in the docs and couldn't find it. In fact, the 9.1 pdf doc of FCMP states that DELETE is in fact supported. So go figure.


Anyways the use case of @KafeelBasha makes it a trivial problem. Which does not preclude the existence of use cases that make it desirable to be able to delete observations.


- Jan.


Quartz | Level 8

Thanks for the explanation.

I came across this example while searching for FCMP documention.


When I use log() function in SAS, I got the same result as we will get after definition the function Vlog() which returns missing(.) for zeros and negative values.


I wonder the particular example is discussed because sas will return the value 0 for zeros and negative values in previous(old) versions. Is it so?


Request you to provide me some examples using FCMP which is more focused towards Mathematics.

Jade | Level 19

Hi @KafeelBasha,


I don't think the LOG function in old versions of SAS "return[ed] the value 0 for zeros and negative values." Wouldn't that have been worse than a cheap pocket calculator?


In this very recent thread PROC FCMP was used to implement a formula involving (a special kind of) an incomplete gamma function.



Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Get the $99 certification deal.jpg



Back in the Classroom!

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

View all other training opportunities.

Discussion stats
  • 4 replies
  • 1 like
  • 4 in conversation