Help using Base SAS procedures

Using Proc FCMP with VVALUEX Function

Accepted Solution Solved
Reply
Highlighted
Contributor
Posts: 23
Accepted Solution

Using Proc FCMP with VVALUEX Function

Hey! I'm new to using Proc FCMP. This is my first attempt. Just experimenting with replacing some repetitive code that's a string of functions with a Proc FCMP function. However, I've run into a little trouble with the VVALUEX function that's in the string I'm trying to replace. Looking for a little help! Using Base SAS 9.4.

 

Here's an example of the code I'm trying to replace. I realize this may not make sense - just playing around with Proc FCMP.

 

LALAE_Lmtd_Paid_LDF_PLmt_Upper = Input(Left(VValueX(Catt('LALAE_',PLmt_Upper_LDF_Char,'Pd'))),8.);
LO_Lmtd_Incd_LDF_Ded_Lower = Input(Left(VValueX(Catt('LO_',Ded_Lower_LDF_Char,'Inc'))),8.);
XS_Incd_LDF_Ded_Lower = Input(Left(VValueX(Catt('XS_',Ded_Lower_XS_LDF_Char,'Inc'))),8.);
LALAE_Lmtd_Incd_LDF_100K = Input(Left(VValueX('LALAE_LDF_100kInc')),8.);

 

Here's the Proc FCMP code and error message:

Proc FCMP Outlib = My_Lib.functions.myfncs;
    Function MyFctrLkp(Fctr_To_Lkp $);
        Fctr = Input(Left(VValueX(Fctr_To_Lkp)),8.);
        Return(Fctr);
    EndSub;
Run;

ERROR: The VVALUEX function is only valid in the DATA step. User defined libraries will be searched for a
definition of this function.
NOTE: Numeric value converted to character for argument 1 of 'LEFT' operation.

ERROR: Cannot find a library containing subroutine VVALUEX.
NOTE: Execution aborted because of errors in program.

 

Here's what I'm trying to accomplish:

LALAE_Lmtd_Paid_LDF_PLmt_Upper = MyFctrLkp(Catt('LALAE_',PLmt_Upper_LDF_Char,'Pd'));
LO_Lmtd_Incd_LDF_Ded_Lower = MyFctrLkp(Catt('LO_',Ded_Lower_LDF_Char,'Inc'));
XS_Incd_LDF_Ded_Lower = MyFctrLkp(Catt('XS_',Ded_Lower_XS_LDF_Char,'Inc'));
LALAE_Lmtd_Incd_LDF_100K = MyFctrLkp('LALAE_LDF_100kInc');

Thanks!

 


Accepted Solutions
Solution
a week ago
Trusted Advisor
Posts: 1,294

Re: Using Proc FCMP with VVALUEX Function

Variables in the program data vector are not accessible within a function.  Consider:

 

proc fCMP Outlib = work.functions.myfncs;
    Function Myfunct();
        Fctr = age;
        Return(Fctr);
    EndSub;
run;
options cmplib=work.functions;
data want;
  set sashelp.class;
  var=Myfunct();
  put var=;
run;

 

which results in VAR=. for all observations.  That's because you have to pass the value of age TO the function in the guise of a function argument (which may or may not also be named age).  Of course no message is generated - only missing values.

 

But VVALUEX is one layer worse, since it is supposed to have variable name as an argument and then go to the pdv to get the value for that variable.  The function compiler knows this, so it tells you VVALUEX can't be used within a function definition.

 

View solution in original post


All Replies
Solution
a week ago
Trusted Advisor
Posts: 1,294

Re: Using Proc FCMP with VVALUEX Function

Variables in the program data vector are not accessible within a function.  Consider:

 

proc fCMP Outlib = work.functions.myfncs;
    Function Myfunct();
        Fctr = age;
        Return(Fctr);
    EndSub;
run;
options cmplib=work.functions;
data want;
  set sashelp.class;
  var=Myfunct();
  put var=;
run;

 

which results in VAR=. for all observations.  That's because you have to pass the value of age TO the function in the guise of a function argument (which may or may not also be named age).  Of course no message is generated - only missing values.

 

But VVALUEX is one layer worse, since it is supposed to have variable name as an argument and then go to the pdv to get the value for that variable.  The function compiler knows this, so it tells you VVALUEX can't be used within a function definition.

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 1 reply
  • 123 views
  • 1 like
  • 2 in conversation