Help using Base SAS procedures

PROC FCMP

Reply
Contributor
Posts: 68

PROC FCMP

Hello

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;
return(.);
endsub;

 

options cmplib=work.Validlog;
data values;
input x;
sf=vlog(x);
datalines;
1
3
0
-4
.
10
;
run;

 

THanks

Super User
Posts: 10,500

Re: PROC FCMP

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

run;

 

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

Super Contributor
Posts: 408

Re: PROC FCMP

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.

 

Contributor
Posts: 68

Re: PROC FCMP

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.

Trusted Advisor
Posts: 1,115

Re: PROC FCMP

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.

Ask a Question
Discussion stats
  • 4 replies
  • 314 views
  • 1 like
  • 4 in conversation